Sha256: 42331d03be4f921094148adbdbdd15f4decd34cc784e4f136279a8429e75d638

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

module CanTango
  class Ability
    class Cache
      class SessionCache < BaseCache
        attr_accessor :session
        attr_reader   :key

        # will be called with :session => session (pointing to user session)
        def initialize name, options = {}
          super # will set all instance vars using options hash
          @cache = cache
          @cache.configure_with :type => :memory
          raise "SessionCache must be initialized with a :session option" if !session
          session[cache_key] = @cache
        end

        def cache_key
          @cache_key ||= :rules_cache
        end

        def store
          session[cache_key]
        end

        def load key
          raise "no key" if key.nil?
          store.load! key
        end

        def save key, rules
          raise "no key" if key.nil?
          store.save!(key, rules)
        end

        def invalidate! key
          raise "no key" if key.nil?
          store.delete(key)
        end

        def cache
          CanTango::Cache::HashCache.instance
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cantango-0.9.4.7 lib/cantango/ability/cache/session_cache.rb
cantango-0.9.4.6 lib/cantango/ability/cache/session_cache.rb
cantango-0.9.4.5 lib/cantango/ability/cache/session_cache.rb
cantango-0.9.4.3 lib/cantango/ability/cache/session_cache.rb