Sha256: 3bfd6add999818f579ebf4f2ceade7cfb64b689b2cbddf8a500e37075ae5a7e0

Contents?: true

Size: 1022 Bytes

Versions: 5

Compression:

Stored size: 1022 Bytes

Contents

module RedisKit
  class Cache
    module Helper
      def self.included( base )
        base.extend ClassMethods
      end

      module ClassMethods
        def cache_namespace( value = nil )
          @cache_namespace = value.to_s unless value == nil
          @cache_namespace || ""
        end

        def cache_timeout( value = nil )
          @cache_timeout = value if value
          @cache_timeout || 60
        end

        def cached( key, timeout = nil, &block )
          timeout ||= cache_timeout
          RedisKit::Cache.get with_namespace( key ), timeout, &block
        end

        def expire( key )
          RedisKit::Cache.expire with_namespace( key )
        end

        protected

        def with_namespace( key )
          cache_namespace != "" ? "#{cache_namespace}:#{key}" : key
        end
      end

      def cached( key, timeout = nil, &block )
        self.class.cached( key, timeout, &block )
      end

      def expire( key )
        self.class.expire key
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
redis-kit-0.1.0 lib/redis-kit/cache/helper.rb
redis-kit-0.0.6 lib/redis-kit/cache/helper.rb
redis-kit-0.0.5 lib/redis-kit/cache/helper.rb
redis-kit-0.0.4 lib/redis-kit/cache/helper.rb
redis-kit-0.0.3 lib/redis-kit/cache/helper.rb