Easy Cache plugin

Plugin details

Easycache lets you easily cache arbitrary data in your Ruby on Rails applications. The plugin makes use of Rails' built-in fragment caching mechanism to store and retrieve any serializable data.

Websitehttp://code.google.com/p/easycache/ Repositoryhttp://easycache.googlecode.com/svn/trunk/ Author Matt Zukowski Tags Cache LicenseUnknown

Documentation

Install the plugin:
ruby script/plugin install http://easycache.googlecode.com/svn/trunk/

EXAMPLES
=============

Once you've installed the plugin, you should be able to do something like this anywhere in your application (in controllers, helpers, etc.):

  foo = ['alpha', 'beta', 'delta', 'gamma']

  # store foo in the cache under the keyname 'greek'
  Easycache.write('greek', foo)

  # retrieve the data stored under keyname 'greek'
  foo = Easycache.read('greek')

  # delete the data stored under keyname 'greek'
  Easycache.delete('greek')


In practice, you will probably want to use caching transparently, so that data is pulled from the cache if available, or from the original source otherwise. For example, say you have a function fetch_some_data_from_LDAP that does a slow LDAP query to retrieve some data. To do this, you would use Easycache's cache method which takes a keyname and a block. If the cache has an entry for the keyname, then the entry will be returned from cache; otherwise the block will be executed and its return value will be stored in the cache and returned.

  data = Easycache.cache('ldap_data') do
    fetch_some_data_from_LDAP
  end


The first time the above code runs, it will execute fetch_some_data_from_LDAP and assign the returned value to data. But the next time it's run, the return value will have come from the cache, so the block won't need to be executed.

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, 7 months ago