Simplecache.rb was dashed off in a rush.
But I still wanted it to be nice to use. So I spent a little bit of time on making it a handy little caching tool.
I also thought that people need a reminder about how to write graceful Ruby code. :) So I spent a little bit of thinking on how I would make a really ruby-centric API.
I ended up with a single function. If the value is in the cache, it'll return it. If the value isn't in the cache, it'll run the block and cache that value. And I assume that most of the time, you aren't going to want to, but it does let you not cache a value. Convention over configuration, guys. :)
example of usage:
$pagecache = Simplecache.new(200,60*60*4)
op = $pagecache.work(curpathstr) {
node = Rm::BaseNode.frompath(curpath)
val = node.http_send(state["command"],state,cgparams,meta)
if meta.nocache?
SimpleCache::CacheControl(val,Simplecache::NOCACHE)
else
val
end
}
$pagecache.expire
Copyright 2007, Ken Wronkiewicz