Wallet is a rails gem that allows you to manage all of your action caching configuration in a single yaml file. It supports TTLs.
For a large project, it’s nice from a systems administration point of view to be able to quickly manage caching in a single place. Having a central YAML file for managing action caching also opens up the possibility of creating backend web interfaces for your application that could allow site administrators of your app to manage the TTL’s from anywhere.
To add wallet to your RAILS app, add a config.gem line like the following to the Rails::Initializer section of your environment.rb:
config.gem "wallet", :lib => 'wallet', :version => '>=0.0.3', :source => "http://gemcutter.org"
Then install the missing gem:
bash$ sudo rake gems:install
Lastly, create an initializer that conditionally loads wallet (e.g., RAILS_ROOT/initializers/wallet.rb)
Wallet.load_from_config # will load from RAILS_ROOT/config/wallet.yml by default.
Once it’s installed, you can create a “wallet.yml” file in your RAILS_ROOT/config directory to manage action caching for your application. Suppose you have a controller “ChannelsController” with actions “cartoon_network” and “current_tv”. At it’s simplest, you could put the following in your “wallet.yml”:
# RAILS_ROOT/config/wallet.yml channels: cartoon_network: current_tv:
Wallet would read this file and setup action caching for the cartoon_network and current_tv actions; it would default the TTL on those actions to 60 seconds. If you wanted a different default, you could add a special “default_ttl:” entry to your “wallet.yml”:
# RAILS_ROOT/config/wallet.yml default_ttl: 30 minutes channels: cartoon_network: current_tv:
Noticed that we simple specified “30 minutes”. The format of the ttls is “d\ (minutes?|days?|hours?)”.
Lastly, suppose you wanted current_tv to cache for 5 hours, but cartoon_network to still use the default:
# RAILS_ROOT/config/wallet.yml default_ttl: 30 minutes channels: cartoon_network: current_tv: 5 hours