From: Gustaf N. <ne...@wu...> - 2021-08-23 08:56:52
|
Dear Maksym, a cache is a collection of entries with certain properties, not to be confused with a cache entry. The call "ns_cache_exists" checks, whether the cache exists (independent of the fact whether the cache has entries or not). The expiration is for cache entries. You can get some overview via the NaviServer "nsstats" module. For example on openacs.org the following caches are defined. The table is sorted by the caches saving the most per request. You see under "Entries" the number of entries per cache. By clicking on the details view of a cache, on can see the entries and per-entry statistics. Here is the page from the "xotcl_object_cache-1", where one can see that certain entries are substantially more often reused from the cache than others. Maybe you are interested whether or not an entry is cached. Actually, this kind of query is rather discouraged, since it is a source for race conditions. Consider the following code: ============================================== BAD [1] set entry foo [2] if {[... in cache $entry ...]} { [3] return [... get from cache $entry ...] [4] } else { [5] set value [... compute something with $entry ...] [6] ... save in cache $entry value [7] } ============================================== In this "BAD" snippet, many things can go wrong in a multi-threaded environment, where also other requests might massage at the same time the same entries, etc. For example it might be the case that the call in [3] fails, when the entry found in [2] is expired/deleted/... between [2] and [3] (we have in NaviServer real concurrency, two threads might run on different cores really simultaneously. Similarly, in line [6], the entry might have been set already by some other thread. ============================================== GOOD set entry foo return [... cache eval $entry { set value [... compute something with $entry ...] }] ============================================== So, it is intentional not to encourage the coding style in small steps as in "BAD". But of course, one can query the the cache entries via "ns_cache_keys $cache_name" Hope this helps -g On 22.08.21 22:44, Maksym Zinchenko wrote: > Hello, I have some question about ns_cache. Im creating cache with > command: ns_cache_create -timeout 1800 -expires 1800 max 5MB When I do > ns_cache_exists max right away, it shows 1 If i wait a little bit, > lets say 5 min, not 30 min as difined (1800 are seconds right?) it > shows 0, cache doesnt exists, if i run command again it shows 1 again. > I dont know whats going on, may be you can advise me. Thank you > Maksym Zinchenko |