require 'dalli'

module Sprockets
  module Cache
    # A simple Memcache cache store.
    #
    #     environment.cache = Sprockets::Cache::MemcacheStore.new
    #
    class MemcacheStore
      def initialize(key_prefix = 'sprockets')
        @memcache   = Dalli::Client.new
        @key_prefix = key_prefix
      end

      # Lookup value in cache
      def [](key)
        data = @memcache.get path_for(key)
        Marshal.load data if data
      rescue ::Dalli::DalliError, Errno::ECONNREFUSED
      end

      # Save value to cache
      def []=(key, value)
        @memcache.set path_for(key), Marshal.dump(value)
        value
      rescue ::Dalli::DalliError, Errno::ECONNREFUSED
      end

      private

      def path_for(key)
        "#{@key_prefix}:#{key}"
      end
    end
  end
end

require 'dalli'

module Sprockets
  class Cache
    # A simple Memcache cache store.
    #
    #     environment.cache = Sprockets::Cache::MemcacheStore.new
    #
    class MemcacheStore
      def initialize(key_prefix = 'sprockets')
        @memcache   = Dalli::Client.new
        @key_prefix = key_prefix
      end

      # Lookup value in cache
      def [](key)
        data = @memcache.get path_for(key)
        Marshal.load data if data
      rescue ::Dalli::DalliError, Errno::ECONNREFUSED
      end

      # Save value to cache
      def []=(key, value)
        @memcache.set path_for(key), Marshal.dump(value)
        value
      rescue ::Dalli::DalliError, Errno::ECONNREFUSED
      end

      private

      def path_for(key)
        "#{@key_prefix}:#{key}"
      end
    end
  end
end

Revert "cache is now a module"
Revert "cache is now a module"

This reverts commit 9fda7b76c24bbcb1ce26b38a2480f0ba3564c514.
