Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

39 lines (29 sloc) 1.07 KB

FileCache is a file-based caching library for Ruby. It's available for download from RubyForge

Note about the current code

I haven't touched this code since I wrote it in 2008! I don't use Ruby much any more. I'm putting it on Github to make it easy for people to find, tweak and extend it. Please feel free to drag it into the 21st century and send me pull requests.


gem install -r filecache

(On a Unix-like system you'll probably want to run that with sudo.)


require 'rubygems'
require 'filecache'

cache =
cache.set(:key, "value")
puts cache.get(:key)     # "value"
puts cache.get(:key)     # nil

# create a new cache called "my-cache", rooted in /home/simon/caches
# with an expiry time of 30 seconds, and a file hierarchy three 
# directories deep
cache ="my-cache", "/home/simon/caches", 30, 3)
cache.put("joe", "bloggs")
puts(cache.get("joe"))   # "bloggs"
sleep 30
puts(cache.get("joe"))   # nil
Jump to Line
Something went wrong with that request. Please try again.