0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Catches ruby objects and caches them
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.15
~> 10.0
~> 3.0

Runtime

>= 0
 Project Readme

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:

gem 'catch_cache'

And then execute:

$ bundle

Or install it yourself as:

$ gem install catch_cache

Usage

To cache objects

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

:flush_cache!

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, after_commit: -> { flush_cache!: -> { lead.id } }
end

:flush_all!

Use :flush_all to clear the cache for all the keys with the suffix defined in cache_id

In your AR model:

class AdminUser < ActiveRecord::Base
  include CatchCache::Flush

  # Everytime the :after_commit AR callback is called,
  # all the Redis caches with suffix "lead_timeline_logs"
  # are going to be flushed

  cache_id :lead_timeline_logs, after_commit: :flush_all!
end

License

The gem is available as open source under the terms of the MIT License.