sinatra-redis-cache 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/Rakefile +1 -1
- data/lib/sinatra/redis-cache.rb +16 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1eb442534222edecf64af54d30a45a7c1d8fe559
|
4
|
+
data.tar.gz: 9128065c4109646cd63074474d5f0e11504eab0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fcd35646a58cd5019cdd7e2cc810df0f0e5704d410a3e91fd1c6abf14594d87c348d5ffb796d7dac45a370a0e817b761af6df9248e6baf19476503944d415dd
|
7
|
+
data.tar.gz: 9620aa4fd0273217853849a684e846ecfa2a199587b9e89b4d50c3399384d2b59dd8d614bcd47fbf35e8419d305f820c72684891fffe55e6d229a2378fd90ef7
|
data/README.md
CHANGED
@@ -7,7 +7,8 @@ A simple redis backed cache for Sinatra applications.
|
|
7
7
|
* Add the gem to your Gemfile
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
|
10
|
+
source 'https://rubygems.org'
|
11
|
+
gem 'sinatra-redis-cache'
|
11
12
|
```
|
12
13
|
|
13
14
|
* Require it in your app after including Sinatra
|
data/Rakefile
CHANGED
data/lib/sinatra/redis-cache.rb
CHANGED
@@ -48,16 +48,29 @@ module Sinatra
|
|
48
48
|
|
49
49
|
def get(key, params={})
|
50
50
|
key = key_with_namespace(key)
|
51
|
-
redis.get(key)
|
51
|
+
string = redis.get(key)
|
52
|
+
unless string.nil?
|
53
|
+
deserialize(string)
|
54
|
+
else
|
55
|
+
false
|
56
|
+
end
|
52
57
|
end
|
53
58
|
|
54
|
-
def store(key,
|
59
|
+
def store(key, object, expires, params={})
|
55
60
|
key = key_with_namespace(key)
|
56
61
|
expires = expires || config.default_expires
|
57
|
-
redis.set(key,
|
62
|
+
redis.set(key, serialize(object))
|
58
63
|
redis.expire(key, expires)
|
59
64
|
end
|
60
65
|
|
66
|
+
def serialize(object)
|
67
|
+
Marshal.dump(object)
|
68
|
+
end
|
69
|
+
|
70
|
+
def deserialize(string)
|
71
|
+
Marshal.load(string)
|
72
|
+
end
|
73
|
+
|
61
74
|
def flush
|
62
75
|
redis.del(all_keys)
|
63
76
|
end
|