Sha256: 74ad0091c6c2c9b464b26a73c4fcfdf49b98886f88550301533aedc1232fa202

Contents?: true

Size: 786 Bytes

Versions: 18

Compression:

Stored size: 786 Bytes

Contents

module QuickTravel
  module Cache
    def cache(key, cache_options = {}, &block)
      QuickTravel::Cache.cache(key, cache_options) do
        block.call
      end
    end

    def self.cache(key, cache_options = {})
      cached_value = cache_store.read(key)
      return cached_value unless cached_value.nil?
      return nil unless block_given?
      cache_options ||= {}
      cache_options[:expires_in] = 1.day unless cache_options.key?(:expires_in)
      yield.tap { |value| cache_store.write(key, value, cache_options) }
    end

    def self.delete(key)
      cache_store.delete(key)
    end

    def self.clear
      cache_store.clear
    end

    def self.cache_store
      @@cache_store
    end

    def self.cache_store=(store)
      @@cache_store = store
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
quicktravel_client-3.7.0 lib/quick_travel/cache.rb
quicktravel_client-3.6.1 lib/quick_travel/cache.rb
quicktravel_client-3.6.0 lib/quick_travel/cache.rb
quicktravel_client-3.5.0 lib/quick_travel/cache.rb
quicktravel_client-3.4.0 lib/quick_travel/cache.rb
quicktravel_client-3.3.0 lib/quick_travel/cache.rb
quicktravel_client-3.2.0 lib/quick_travel/cache.rb
quicktravel_client-3.1.0 lib/quick_travel/cache.rb
quicktravel_client-3.0.0 lib/quick_travel/cache.rb
quicktravel_client-2.9.0 lib/quick_travel/cache.rb
quicktravel_client-2.8.0 lib/quick_travel/cache.rb
quicktravel_client-2.7.0 lib/quick_travel/cache.rb
quicktravel_client-2.6.0 lib/quick_travel/cache.rb
quicktravel_client-2.5.0 lib/quick_travel/cache.rb
quicktravel_client-2.4.1 lib/quick_travel/cache.rb
quicktravel_client-2.4.0 lib/quick_travel/cache.rb
quicktravel_client-2.3.1 lib/quick_travel/cache.rb
quicktravel_client-2.3.0 lib/quick_travel/cache.rb