Sha256: b23aac22f1f2023b83da6c20786bdfec01ba32e69c7266bd155618b9e1af896b
Contents?: true
Size: 1.47 KB
Versions: 1
Compression:
Stored size: 1.47 KB
Contents
# CatchCache An easy way to manage caching and flushing of Ruby objects. Especially useful when you are speeding a very slow API or page. ## Installation Add this line to your application's Gemfile: ```ruby gem 'catch_cache' ``` And then execute: $ bundle Or install it yourself as: $ gem install catch_cache ## Usage ```ruby class ServiceWithAVerySlowQuery include CatchCache::Cache def query lead = get_some_lead catch_then_cache("lead_timeline_logs_#{lead.id}") do # Your very slow query which # returns a bunch of Ruby objects end end end ``` In your AR model: ```ruby In your AR model: class LoanApplication < ActiveRecord::Base include CatchCache::Flush belongs_to :lead # Everytime the :after_commit AR callback is called, # the Redis cache with id "lead_timeline_logs_#{lead.id}" # is going to be flushed cache_id :lead_timeline_logs, -> { lead.id } end ``` You could also register callbacks using `cache_id` ```ruby class LoanApplication < ActiveRecord::Base include CatchCache::Flush cache_id :lead_timeline_logs, after_commit: :do_something_with_cache cache_id :central_page_loan_plans, after_commit: -> { do_something_with_cache } end ``` ## API - ### flush_all! Clears cache for all the keys registered with `cache_id` ```ruby cache_id :lead_timeline_logs, after_commit: :flush_all! ``` ## License The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
catch_cache-0.0.5 | README.md |