= Easycache 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. This is especially useful when you want to store data from external sources like LDAP or Web Services, for which Rails does not currently offer an integrated caching mechanism. Visit http://code.google.com/p/easycache/ for more information. === INSTALLATION From the command line, cd into your Rails application's root directory and run: 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.