in reply to Re: Cache::MemoryCache
in thread Cache::MemoryCache

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.

Replies are listed 'Best First'.
Re: Re: Re: Cache::MemoryCache
by zengargoyle (Deacon) on Jul 19, 2003 at 04:57 UTC

    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.
Re: Re: Re: Cache::MemoryCache
by diotalevi (Canon) on Jul 19, 2003 at 01:00 UTC

    Use FileCache, then its persistent.

Re: Re: Re: Cache::MemoryCache
by sauoq (Abbot) on Jul 19, 2003 at 01:03 UTC
    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.";