Re: [Zope-dev] RAM Cache Manager "next_cleanup" not working?
"Júlio Dinis Silva" wrote:
Looking into lib.python.Products.standardCacheManagers.RAMCacheManager.py
I found something it looks like a problem in the code and I came to a solution which solves the problem in subject althougt I dont know If this is a safe solution, It works for me.
The theory behind the current solution is that a cache cleanup operation occurs:
- only if a certain amount of time has passed since the last cleanup, and
- only when adding a new entry to the cache.
Then, even during a cleanup, nothing is removed if the number of entries is below the threshold.
The idea is that cache hits should be as fast as possible. Cleanup occurs on cache misses instead. The only side effect is that watching for entries to get cleaned up on the stats page won't act as you might expect. The number of entries will *always* go above the threshold. The entries will be cleaned up next time there's a cache *miss*.
This is *not* a bug. But maybe we could "fix" it by executing a cleanup every time users look at the stats page. :-)
Another idea is for you to create your own cache manager. In fact we (Digital Creations) encourage the creation of alternate cache managers.
Hi Shane, Thanx for your reply. I understand the theory you explained to me. But even that theory being correct and now I know better how the RAM Cache Manager works, and even thinking of doing another cache manager, another point of my post is that something is not working: I'm testing this, caching a page that only creates one entry in the cache, because there is nothing different with that page to create multiple cache entries (Query_string vars, or other stuff), i.e, the "cache keys" of this page is always the same it doesnt receive any parameters to create a different entry. And taking this in mind even with a threshold of 0 (zero) the next_cleanup value is never tested in the code. So this is what I think is somehow wrong with the code:
The theory behind the current solution is that a cache cleanup operation occurs:
- only if a certain amount of time has passed since the last cleanup, and
- only when adding a new entry to the cache.
Soo what I was not able to reproduce with the current RAM Cache Manager code is the "certain amount of time has passed" condition. Because of that there was my solution of returning "default" in the ZCache_get code which I agree with you it slows cache hits, but was the only way I got to put the interval_period to work. If you could be so kind and do a little test: -create a dtml method with only this line of code: <dtml-var ZopeTime> -create a Ram cache manager, define 0 (zero) for the threshold and 5 seconds for the cleanup interval, and associate your dtml method with this Ram Cache manager. -Then go to a browser and request several times the dtml method and you will see that the zopetime returned by the dtml method never changes, even after 5 seconds. Isnt this suppose to work? I mean, there is a threshold of 0 (zero) so when the 5 seconds pass the call to cleanup should cleanup this entry because there will be 1 entry and the threshold is 0 (zero). Thanx again for your reply, Best Regards, Julio Dinis Silva _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
On Thu, 19 Jul 2001, J�lio Dinis Silva wrote:
-create a dtml method with only this line of code: <dtml-var ZopeTime> -create a Ram cache manager, define 0 (zero) for the threshold and 5 seconds for the cleanup interval, and associate your dtml method with this Ram Cache manager. -Then go to a browser and request several times the dtml method and you will see that the zopetime returned by the dtml method never changes, even after 5 seconds.
Isnt this suppose to work? I mean, there is a threshold of 0 (zero) so when the 5 seconds pass the call to cleanup should cleanup this entry because there will be 1 entry and the threshold is 0 (zero).
No, it's not supposed to work. :-) Create another DTML method and associate it with the same cache manager, then view the new DTML method. This will cause ZCache_set() to be called and *then* the cache will be cleaned up. What you really want to use is the max_age parameter. (It might only be in Zope 2.4.x.) You want the cache of the DTML method to expire after a certain time period, right? Use max_age. When the cache retrieves an expired cache entry, the entry will be removed and later replaced. Each parameter serves a very distinct purpose. The max_age parameter is meant for cache duration control. The threshold parameter is meant for balancing memory use with cache size. And the cleanup interval is to balance memory management with cache performance overhead. Does that make sense? Shane
participants (2)
-
J�lio Dinis Silva -
Shane Hathaway