Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

persistent cache using Cache::FileCache

by johnnywang (Priest)
on Nov 05, 2004 at 02:20 UTC ( [id://405361]=perlquestion: print w/replies, xml ) Need Help??

johnnywang has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm trying to find a way to create a persistent cache, i.e., so that different processes can access the same cache (even after process restarts), and database is not an option. I was trying to use IPC::Shareable to store it, but was running into problems with the number of semaphores. So now I'm looking into Cache::FileCache, it works fine within a process, but the cached file disappears when the creating process exits. Is there any way to keep it around and re-use it when a new process starts? how about locking? Thanks.

Replies are listed 'Best First'.
Re: persistent cache using Cache::FileCache
by perrin (Chancellor) on Nov 05, 2004 at 04:39 UTC
    I've never seen the behavior you're describing. It should not remove the files unless you intentionally clear the cache. However, Cache::FileCache is not very fast. Using BerkeleyDB or Cache::FastMmap or even DBD::mysql is much faster.
Re: persistent cache using Cache::FileCache
by Nitrox (Chaplain) on Nov 05, 2004 at 02:35 UTC
    You may find DBM::Deep of interest. Its similar to Cache::FileCache but can also provide the "persistance" that you are looking for(as long as you don't call clear()) as well as locking.

    -Nitrox

Re: persistent cache using Cache::FileCache
by bpphillips (Friar) on Nov 05, 2004 at 03:14 UTC
    We use Cache::FileCache extensively (HTML::Mason has hooks built-in to use it) and I've never experienced the probably you're describing of the cache file disappearing. I just tried this test code and each time I run the script, I get the PID of the previous process out of the cache:
    #!/usr/bin/perl use strict; use Cache::FileCache; my $c = new Cache::FileCache({'namespace'=>"foo"}); warn "Previous PID: " . $c->get("pid"); $c->set("pid"=>$$); warn "This PID: " . $c->get("pid");
Re: persistent cache using Cache::FileCache
by gaal (Parson) on Nov 05, 2004 at 05:20 UTC
    Why are databases not an option, speed?

    You might want to try memcached frontending a database. That should be very fast and very scalable.

      It is very scalable, but it's not as fast as BerkleyDB or Cache::FastMmap for local storage. It's also not really faster than MySQL for simple primary key lookups.
        Hmmm, have you run benchmarks? For reads, it's going to be "fast": faster, I'd expect, than BerkleyDB, and more or less as fast as MySQL if indeed the queries are for simple indexed keys, significantly faster otherwise. I don't know anything about Cache::FastMap. (But I'll read up on it; sounds interesting!)

        If you have lots of RAM, and your data is big, too, memcached will outperform MySQL because you can run several daemons and circumvent the process size limit problem. (Talking 32-bit here.)

Re: persistent cache using Cache::FileCache
by fuzzyping (Chaplain) on Nov 05, 2004 at 02:30 UTC
    I haven't tried it, but would IPC::SharedCache meet your needs? Sounds like it allows for caching between processes using cache in memory.

    -fp
      It has poor performance. Much worse than Cache::FileCache.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://405361]
Approved by atcroft
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-03-28 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found