Class: Sprockets::Cache::MemcacheStore

Inherits:
Object
  • Object
show all
Defined in:
lib/sprockets/cache/memcache_store.rb

Overview

A simple Memcache cache store.

environment.cache = Sprockets::Cache::MemcacheStore.new

Instance Method Summary collapse

Constructor Details

#initialize(key_prefix = 'sprockets') ⇒ MemcacheStore

Returns a new instance of MemcacheStore.



10
11
12
13
# File 'lib/sprockets/cache/memcache_store.rb', line 10

def initialize(key_prefix = 'sprockets')
  @memcache   = Dalli::Client.new
  @key_prefix = key_prefix
end

Instance Method Details

#[](key) ⇒ Object

Lookup value in cache



16
17
18
19
20
# File 'lib/sprockets/cache/memcache_store.rb', line 16

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

#[]=(key, value) ⇒ Object

Save value to cache



23
24
25
26
27
# File 'lib/sprockets/cache/memcache_store.rb', line 23

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