bot403 has asked for the wisdom of the Perl Monks concerning the following question:
Just looking for a little advice before I try to re-implement the wheel.
I'm looking for an interface/module/method that will help me manage a few hundred of potentially large files 1M->200GB as a "cache".These files are very expensive computationally to create but can easily be re-made so we're looking to cache results on the filesystem. If they get destroyed because the cache had to purge them then we'll just re-create them.
In a nutshell I want to tie a set of files to a caching algorithm.
I've looked into CHI, Cache::Cache and Cache::File but they seem to be missing a few of my requirements.
1. I want to tell the cache what the object size is and have it free up that space for me if possible.
2. I want to store the object myself with my own filename.
Processes that cant talk to perl need to be able to find the files by their filename.
3. I don't care about cache speed. Get/Set requests will be measured in the dozens per hour.
I really want is a size-aware cache where I can say:
1. I want to store a 100GB file called Foofile.dat in the cache. Is there room?
2. No? Then please make 100GB for me by removing files according to LRU or some other cache policy.
3. Is there room now? Then allocate a 100GB block of space in the cache where Foofile.dat will go.
This 100GB is gone and cant be used by another process unless its purged.
4. Kickoff other process that writes Foofile.dat
later....some other process wants the file
1. Is Foofile.dat in the cache? Either ask in perl or look in the cache directory with ls or stat..etc.
2. Yes? Ok great. I'll read Foofile.dat myself.
3. No? Awww....handle fail condition.
Does such a thing already exist or shall I have to make one? I haven't poked too deep but I may be able to extend one of the cache modules in CPAN.
Update: It looks like writing a CHI::Driver is the way to go. After looking at the source to CHI::Driver::File it seems simple enough and doable and I'll probably just take CHI::Driver::File as a base and fork it for my purposes.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Managing a "cache" of files
by Tanktalus (Canon) on Jul 28, 2009 at 16:13 UTC | |
by bot403 (Beadle) on Jul 28, 2009 at 16:33 UTC | |
|
Re: Managing a "cache" of files
by perrin (Chancellor) on Jul 28, 2009 at 16:32 UTC | |
|
Re: Managing a "cache" of files
by Illuminatus (Curate) on Jul 28, 2009 at 16:36 UTC | |
by bot403 (Beadle) on Jul 28, 2009 at 19:09 UTC |