Sha256: 88ac76b7a8db153a9956aa77c109f0357ac0a1f83c38319f1c87b465ee345675

Contents?: true

Size: 728 Bytes

Versions: 2

Compression:

Stored size: 728 Bytes

Contents

require 'singleton'

module InfoparkComponentCache
  # @author Tomasz Przedmojski <tomasz.przedmojski@infopark.de>
  #
  # Trivial wrapper around underlying cache storages.
  # This class or any other class that inherits it *must*
  # respect Rails.application.config.action_controller.perform_caching
  # setting.
  class CacheStorage
    include Singleton

    def exist?(key)
      enabled? && Rails.cache.exist?(key)
    end

    def read(key)
      Rails.cache.read(key) # you can still read the cache if you wish...
    end

    def write(key, value)
      Rails.cache.write(key, value) if enabled?
    end

    # @private
    def enabled?
      Rails.application.config.action_controller.perform_caching
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
infopark_component_cache-1.1.0 lib/infopark_component_cache/cache_storage.rb
infopark_component_cache-1.0.0 lib/infopark_component_cache/cache_storage.rb