Sha256: f1696c6f506f602da4d4a96a29275d6d60063b1f12a107aecf374498c4f02d3a

Contents?: true

Size: 888 Bytes

Versions: 1

Compression:

Stored size: 888 Bytes

Contents

require 'blanket_cachekey/version'
require 'rails'
require 'blanket_cachekey/engine'

module BlanketCachekey

  class << self
    attr_accessor :cache
  end


  def self.included(model)
    model.class_eval do

      after_save :invalidate_blanket_cachekey
      after_destroy :invalidate_blanket_cachekey

      private

      def invalidate_blanket_cachekey
        self.class.invalidate_blanket_cachekey
      end


      class << self


        def blanket_cachekey 
          BlanketCachekey.cache.fetch(blanket_cachekey_name) do
            "#{table_name}:#{Time.now.to_i}:#{Time.now.nsec}"
          end
        end

        def invalidate_blanket_cachekey
          BlanketCachekey.cache.delete blanket_cachekey_name
        end

        private 

        def blanket_cachekey_name
          "blanket_cachekey:name:#{self.table_name}"
        end


      end

    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blanket_cachekey-0.0.1 lib/blanket_cachekey.rb