Sha256: ad6245fd78b5ada921a97375cdeb8fa2f54cf872f66e7cd9604cf983bef37516

Contents?: true

Size: 822 Bytes

Versions: 7

Compression:

Stored size: 822 Bytes

Contents

require 'forwardable'

module LockBoxCache
  class Cache
    extend Forwardable
    def_delegators :@cache, :write, :read, :delete
    
    class RailsCache
      def write(key, value)
        Rails.cache.write(key, value)
      end

      def read(key)
        Rails.cache.read(key)
      end

      def delete(key)
        Rails.cache.delete(key)
      end
    end

    class HashCache
      def initialize
        @store = Hash.new
      end

      def write(key, value)
        @store[key] = value
      end

      def read(key)
        @store[key]
      end

      def delete(key)
        @store.delete(key)
      end
    end
    
    def initialize(use_rails_cache=true)
      if use_rails_cache && defined?(Rails)
        @cache = RailsCache.new
      else
        @cache = HashCache.new
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lockbox_middleware-1.5.1 lib/lockbox_cache.rb
lockbox_middleware-1.5.0 lib/lockbox_cache.rb
lockbox_middleware-1.4.2 lib/lockbox_cache.rb
lockbox_middleware-1.4.1 lib/lockbox_cache.rb
lockbox_middleware-1.3.1 lib/lockbox_cache.rb
lockbox_middleware-1.3.0 lib/lockbox_cache.rb
lockbox_middleware-1.2.3 lib/lockbox_cache.rb