From: Maksym Z. <siq...@gm...> - 2021-08-24 00:40:23
|
Thank you, for explanation Gustaf. Error must be somewhere in my code. What I'm trying to accomplish is create session. Ive got this code from somewhere on the internet, I don’t even know where. And modified it little bit. Basically, Im creating session for each virtual server like: $domain_sessions, if user logs in I’m creating uuid as cache key and as a cache value tcl dict with info related to user, such as username, real name etc. I have a persistence function which saves this data to db table, updates session timestamp etc. But lately, user logs in start working and randomly redirected back to the login screen because data in db is not the same as in cache, so I'm a little bit lost, still trying to figure out what’s going on. If you know any session package or code example I would appreciate tremendously On Mon, Aug 23, 2021 at 7:57 AM Gustaf Neumann <ne...@wu...> wrote: > 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 > > > _______________________________________________ > naviserver-devel mailing list > nav...@li... > https://lists.sourceforge.net/lists/listinfo/naviserver-devel > |