Skip to content

Ruby gem that adds simple functions to invalidate single columns as a cache on an ActiveRecord models.

License

Notifications You must be signed in to change notification settings

twohlix/database_cached_attribute

Repository files navigation

DatabaseCachedAttribute

Code Climate Build Status Gem Version

Description

Ruby gem that adds simple functions to invalidate single columns as a cache on an ActiveRecord models.

Using DatabaseCachedAttribute

DatabaseCachedAttribute is an ActiveSupport Concern and creates 1 set of helpers on inclusion and another on a different usage.

 gem install database_cached_attribute
class YourFunClass < ActiveRecord::Base
  include DatabaseCachedAttribute
  
  database_cached_attribute :your_column
end

That will create a few functions for your model such as:

your_obj = YourFunClass.new
your_obj.invalidate_your_column #invalidates and persists the change to the db if appropriate
your_obj.cache_your_column      #attempts to save your cache change to the db if appropriate
your_obj.only_your_column_changed? #tells you if your objects only change is that column

These helpers let you do nice things in your model like:

class YourFunClass < ActiveRecord::Base
  include DatabaseCachedAttribute
  database_cached_attribute :your_column

  has_many :other_things, before_add: :invalidate_your_column
end

About

Ruby gem that adds simple functions to invalidate single columns as a cache on an ActiveRecord models.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages