Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Hi Monks I am trying to use the CHI module but am coming up against erratic behaviour. There may well be good reason for it but I am stumbling along in the dark at the moment and so hope someone can point me in the right direction as to what is going on. In my main code I create an accessor to the cache. I am using Moose so it looks like: has chi => (is => 'rw', isa => 'Any', default => sub{ CHI->new( driver => 'Memory', global => 1, serializer => 'Data::Dumper', namespace => 'vbsite' ) } );(I could probably do better than 'Any' and will get to that when I work out what it should be!) ... and to store items: $self->chi->set( $key_hashref, $to_store, 'never' );Note I have experimented with the duration setting with no substantial difference in results. Now I wrote a short inspector script to tell me what keys were in the cache at the moment when the script is run:
So I run the main program until it seems to be caching, then I run the inspector script. Sure enough I get something like:
which looks good. But then if I keep running the inspector script (without changing anything at all, without running the main program again or any other programs) I get a different result:
... and in fact if I run it over and over, I seem to get a different result each time. Now I dont know if it is designed so ->get_keys only returns a key if the cache would have returned a cached value if it was requested at that moment, and does not return a key if the cache decides this particular request should miss the cache. However it is causing me problems because, when my main code performs a 'save' operation I would like to inspect all keys in the cache and remove those items that would be affected by the saved file. Because ->get_keys does not seem to reliably return all the keys in the cache this doesnt seem to work Alternatively perhaps it *should* consistently return all keys in the cache, and there is something wrong with my implementation? Though my implementation really is not complex and it is difficult to see what I could be doing to cause the error. Can anyone shed any light? Your help greatly appreciated... In reply to some caching issues using CHI by tomgracey
|
|