soveran edited this page Sep 13, 2010 · 3 revisions
Clone this wiki locally


Ultra slim file-based cache.


require ‘drawer’ cache = Drawer.new(‘db/development.drawer’) cache.get(‘foo’) #=> nil cache.set(‘foo’, 123) cache.get(‘foo’) #=> 123 cache.flush_all cache.get(‘foo’) #=> nil cache.set(‘bar’, 456) cache.set(‘baz’, 789) cache.get_multi(‘bar’, ‘baz’) #=> [456, 789]

An optional second parameter is a class to be used as the persistence layer.
By default, DrawerStore is used, but it can be replaced by any class that
provides load and save methods. For example:

cache = Drawer.new(some_file, MyStoreClass)

Now, MyStoreClass.load(some_file) and MyStoreClass.save(@cache, some_file) will
be used for retrieving and saving the cached contents.

From the command line

First, create an empty file. It will be used to store the cache:

$ touch my_file $ drawer my_file

After this, you are prompted in an interactive session (IRB) where you can use the typical cache
methods, like set, get, get_multi, remove, flush_all.

$ drawer my_file >> get “foo” => nil >> set “foo”, 123 => 123 >> set “bar”, 456 => 456 >> get “foo” => 123 >> self => Drawer count: 0. Type ‘cache’ to view the content. >> get_multi “foo”, “bar” => [123, 456] >> flush_all => {}

You can of course use this tool to explore your existing databases, but only if they
where created with the default storage (currently DrawerStore).


$ gem sources -a http://gems.github.com (you only have to do this once) $ sudo gem install soveran-drawer


Michel Martens

Copyright © 2008 Michel Martens.
Released under the MIT license.