pileofrogs has asked for the wisdom of the Perl Monks concerning the following question:
Greetings Monks!
I have a script that runs often, is run by lots of different processes, and takes a long time. It is basically testing the environment to see if whatever called it can proceed.
I should be able to cache the results in some way, but I want to make sure I do the caching properly.
There is no "Key" for this cache. All answers are the same. A database is not appropriate, so I need to handle any atomic/concurrency stuff.
- If the cache is fresh, read it and go away
- If the cache is stale...
- Try to get exclusive lock
- Got lock? Do tests, write results to cache, go away
- Didn't get lock????
- Try to get exclusive lock
This is where it gets more complicated. Do I wait around for whoever has the lock to finish? Do I wait only if the locking process is doing the tests? How do I handle a situation where a locking process has wandered off into oblivion and hasn't released the lock?
I'm on linux and I'm thinking with flock, but I'm open to non-flock ideas.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Concurrent Cache Pattern
by BrowserUk (Patriarch) on Aug 03, 2012 at 23:55 UTC | |
by pileofrogs (Priest) on Aug 07, 2012 at 20:59 UTC | |
Re: Concurrent Cache Pattern
by flexvault (Monsignor) on Aug 04, 2012 at 10:40 UTC | |
Re: Concurrent Cache Pattern
by Anonymous Monk on Aug 03, 2012 at 18:17 UTC | |
Re: Concurrent Cache Pattern
by sundialsvc4 (Abbot) on Aug 04, 2012 at 17:58 UTC |