Closed marcos-guerrero closed 1 year ago
Hello,
That's an expected behavior to be honest, not a bug.
The item object is statically still present in the Phpfastcache internal storage.
So you're basically just trying to write an expired item to Redis which return false, as expected.
You have two options:
useStaticItemCaching
, see options in WikiSo, It's not a bug, it's a feature :D
Thank you very much for your attention and fast answer. Ok, I'll study the options and decide what to do, but for me maybe the best option is to set ttl everytime I save an item, because relying on defaultTtl is not giving the behaviour I expected
The default ttl only work for new cache items, that does not exist in the internal storage. If an object with the specified key exists in the cache storage or in the backend, the default values are not applied.
The default ttl only work for new cache items, that does not exist in the internal storage. If an object with the specified key exists in the cache storage or in the backend, the default values are not applied.
Thank you again for your help, yes, I understand, that's why I'm thinking of not using defaulTtl anymore and substitute it with an explicit expiresAfter() that works in new and already existing items
The static storage is intended to avoid querying the original backend if the item has been already fetched using getItem methods. If you disable useStaticItemCaching
, the core will ignore static storage and will always query the original backend. Therefore if the item has expired and the backend returns nothing, you will get a new not hit * fresh item with default TTL applied (900s)
The static storage is intended to avoid querying the original backend if the item has been already fetched using getItem methods. If you disable
useStaticItemCaching
, the core will ignore static storage and will always query the original backend. Therefore if the item has expired and the backend returns nothing, you will get a new not hit * fresh item with default TTL applied (900s)
I understand that disabling static storage is easy and no code changes are required, but sure the performance will be affected, so having the chance to tweak my set($key, $value, $ttl) method and call expiresAfter() always (with default or explicit ttl) maybe is the solution with minimum code changes and not sacrifice performance... Don't you think so?
Disabling static storage may slightly reduce performances for applications that critically need fresh cache item. In your case, I think you should, indeed, always specify the desired expiration time to be POLA-compliant :P
POLA-compliant
Sorry, I don't catch it ...
POLA-compliant
Sorry, I don't catch it ...
Principe Of Last Astonishment, look on Wikipedia. Basically it means, always be as much explicit as you can, in order to avoid any undesired behavior from your code :)
Ok! Interesting, thank you very much! I understand Last but not least, I want to thank you for your software, phpfastcache rocks! It made our migration from apcu and memcached to redis very easy, and the tags feature is very very useful!
Ok! Interesting, thank you very much! I understand Last but not least, I want to thank you for your software, phpfastcache rocks! It made our migration from apcu and memcached to redis very easy, and the tags feature is very very useful!
Thank you :) Everything's good for you now ?
Ok! Interesting, thank you very much! I understand Last but not least, I want to thank you for your software, phpfastcache rocks! It made our migration from apcu and memcached to redis very easy, and the tags feature is very very useful!
Thank you :) Everything's good for you now ?
Aye! Everything is ok for me now!
Great :D
What type of issue is this?
Incorrect/unexpected/unexplainable behavior
Operating system + version
ubuntu 22.04
PHP version
8.2.3
Connector/Database version (if applicable)
redis_version:7.0.8
Phpfastcache version
9.1.2 🔶
Describe the issue you're facing
I'm using Redis Driver with defaultTtl configured, so usually I don't use expiresAfter() nor expiresAt() Item API methods
Once the item is in the cache pool (because I just saved it with save() ItemPool method or because I retrieved it with getItem() method) , I sleep for defaultTtl + 1 seconds , just to be sure that the item is expired. Then, I save it again.
Expected behavior
The expected behaviour is the item to be saved no matter if explicit ttl is set or not
Code sample (optional)
Suggestion to fix the issue (optional)
No response
References (optional)
No response
Do you have anything more you want to share? (optional)
No response
Have you searched in our Wiki before posting ?