module ProstoCache

This library provides a simple way to cache model and to access this cache in some canonical way. Any changes to the model’s objects will automatically result in cache reload. Cache reload in other ruby processes of same app will be triggered as well, but with some delay (currently up to 60 seconds). If the delay in cache reloading is not an option, well, this simple library will not work for you, and you will have to use something fancier, like Memcached.

Usage:

Public Class Methods

fail_on_missing_value?(litmus) click to toggle source
# File lib/prosto_cache/prosto_hash.rb, line 33
def self.fail_on_missing_value?(litmus)
  case litmus
  when Symbol
    true
  when String
    false
  else
    raise ArgumentError, "Unknown type of cache key #{litmus.inspect}"
  end
end
included(cl) click to toggle source
# File lib/prosto_cache/prosto_model_cache.rb, line 208
def self.included(cl)

  cl.after_save { cl.cache.invalidate }

  class << cl

    def cache
      @cache ||= ProstoModelCache.new self, @accessor_keys, @sort_keys
    end

    def cache_accessor_keys(keys)
      @accessor_keys = keys
    end

    def cache_sort_keys(keys)
      @sort_keys = keys
    end
  end
end