in reply to Cache::MemoryCache

FileCache is persistent across processes. MemoryCache isn't.

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re: Re: Cache::MemoryCache
by Anonymous Monk on Jul 19, 2003 at 00:51 UTC
    Is there a way for me to make it persistent? I want to hit the db, populate the object and cache it in memory and avoid having to hit the db again, next time I have a request for that object.

      maybe, just maybe you can use Cache::SharedMemoryCache

      have one program that that stays running to hold the cache in memory while other programs come and go.

      # holdcache.pl use Cache::SharedMemoryCache; my %cache_options_= ( 'namespace' => 'MyNamespace', ); my $c = Cache::SharedMemoryCache->new( \%cache_options ) or die( "Couldn't instantiate SharedMemoryCache" ); while (1) { sleep 300; } __END__

      should do to keep the cache open.

      $ perl holdcache.pl & $ perl -e 'use Cache::SharedMemoryCache;$c=Cache::SharedMemoryCache->n +ew({namespace=>"MyNamespace"}) or die;$c->set("foo",1);' $ perl -e 'use Cache::SharedMemoryCache;$c=Cache::SharedMemoryCache->n +ew({namespace=>"MyNamespace"}) or die;$x=$c->get("foo");print $x,$/' 1

      presto!

        I recommend you use Cache::FileCache instead of Cache::SharedMemoryCache. The file cache is much faster. If you want to go even faster, Cache::Mmap is a good choice.

      Use FileCache, then its persistent.

      Is there a way for me to make it persistent?

      Uh... no. You could get a close approximation by using FileCache and a RAM disk.

      -sauoq
      "My two cents aren't worth a dime.";