Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache Backend increment/decrement bug #12109

Closed
kowach opened this issue Aug 8, 2016 · 1 comment
Closed

Cache Backend increment/decrement bug #12109

kowach opened this issue Aug 8, 2016 · 1 comment
Assignees
Labels
bug A bug report status: medium Medium
Milestone

Comments

@kowach
Copy link

kowach commented Aug 8, 2016

There is a bug in all cache backends that use their internal functions (for example apc_inc). The value that is incremented or decremented must be stored as int, but all frontends use serialization. If you serialize value it becomes some sort of string and then inc/dec fails.

    $cache->save('myval',1);

   // value is stored as: "i:1;"
   // phalcon/cache/frontend/data.zep#L132:  
   // public function beforeStore(var data) {  return serialize(data);   }

   $result = $cache->increment('myval');
   // apc_inc("i:1;")

   // returns false

The solution would be to check if frontend uses serialization then don't use internal functions (you loose atomic operation) and risk race conditions and value incorrectly incremented in two separate threads.
Or allow normal expiration time in phalcon/cache/frontend/none.zep so you can use it as frontend without serialization.

@sergeyklay
Copy link
Contributor

Fixed in the 3.0.x branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: medium Medium
Projects
None yet
Development

No branches or pull requests

3 participants