A simple, redis-backed caching plugin for Rails.
What is it for?
It's mainly for caching read-only API calls for a set-period of time.
What does it do?
It caches controller actions based on type, and can expire the cache whenever you want.
But Rails already has caching built-in...
Yes, but it doesn't auto-expire the files it writes to disk. Also, because Cachemere is redis-backed, it uses mainly RAM to access cached files.
Add Cachemere to your Gemfile**
In your controller, create a before and after filter for Cachemere.
before_filter :cache_start after_filter :cache_end
Create the above filters and start caching!
def cache_start ::(request, :json, self) # Where ":json" is the response type end def cache_end ::end_caching(response, 60) # Where '60' is how long you want to keep the cache (in seconds) end
All done! Happy caching!
Head of R&D
Copyright (c) 2011, Kishyr Ramdial.
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.