Class: Sprockets::Cache::RedisStore

Inherits:
Object
  • Object
show all
Defined in:
lib/sprockets-cache-redis-devio/redis_store.rb

Overview

A simple Redis cache store.

environment.cache = Sprockets::Cache::RedisStore.new($redis)

Instance Method Summary collapse

Constructor Details

#initialize(redis_conn, key_prefix = 'sprockets') ⇒ RedisStore

Returns a new instance of RedisStore.



8
9
10
11
# File 'lib/sprockets-cache-redis-devio/redis_store.rb', line 8

def initialize(redis_conn, key_prefix = 'sprockets')
  @redis = redis_conn
  @key_prefix = key_prefix
end

Instance Method Details

#[](key) ⇒ Object

Lookup value in cache



14
15
16
17
# File 'lib/sprockets-cache-redis-devio/redis_store.rb', line 14

def [](key)
  data = @redis.get path_for(key)
  Marshal.load data if data
end

#[]=(key, value) ⇒ Object

Save value to cache



20
21
22
23
# File 'lib/sprockets-cache-redis-devio/redis_store.rb', line 20

def []=(key, value)
  @redis.set path_for(key), Marshal.dump(value)
  value
end