Last Updated: February 25, 2016
·
264
· exlee

Simple file-based persistance for Ruby

Fast to use and setup method to cache intermediate result for utilities using ruby's gem named filecache. Excerpt from the README:

require 'rubygems'
require 'filecache'

# 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 = FileCache.new("my-cache", "/home/simon/caches", 30, 3)
cache.put("joe", "bloggs")
puts(cache.get("joe")) # Returns bloggs
sleep 30
puts(cache.get("joe")) # Returns nil