sprockets-cache-redis 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
@@ -2,17 +2,23 @@ require 'digest/md5'
|
|
2
2
|
|
3
3
|
module Sprockets
|
4
4
|
module Cache
|
5
|
+
# A simple Redis cache store.
|
6
|
+
#
|
7
|
+
# environment.cache = Sprockets::Cache::RedisStore.new($redis)
|
8
|
+
#
|
5
9
|
class RedisStore
|
6
10
|
def initialize(redis_conn, key_prefix = 'sprockets')
|
7
11
|
@redis = redis_conn
|
8
12
|
@key_prefix = key_prefix
|
9
13
|
end
|
10
14
|
|
15
|
+
# Lookup value in cache
|
11
16
|
def [](key)
|
12
17
|
data = @redis.get path_for(key)
|
13
18
|
Marshal.load data if data
|
14
19
|
end
|
15
20
|
|
21
|
+
# Save value to cache
|
16
22
|
def []=(key, value)
|
17
23
|
@redis.set path_for(key), Marshal.dump(value)
|
18
24
|
end
|