Super simple caching for Ruby
class Product
attr_cached :orders_count
def orders_count
# ...
end
endChoose when to use the cached value
product.orders_count # not cached
product.cached_orders_count # cachedForce a re-cache [master]
product.cache_orders_count!Add this line to your application’s Gemfile:
gem 'cached_attributes'Works with any ActiveSupport cache store. For Rails, Rails.cache is used by default.
Set the cache store with:
CachedAttributes.cache = ActiveSupport::Cache::MemoryStore.newEveryone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features