gibson 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +17 -0
- data/lib/active_support/cache/gibson_store.rb +101 -0
- data/lib/gibson/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjA4ZDg5ZjE0MDY4NTU3OTZlOTQyYWRjYWRiZTM2YjI1NDllNGM2OQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzVhMWYyOWFmZGU1YTRlYzdkOGMzMzM5ZjMxNGM0Y2QyZmYwZGZjYw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjZlMTlmMjg1YmYxNDA4YmJlYjZkY2I1Yjc5ZjQ3NmNiN2Y4ZDZkNmNmYTZj
|
10
|
+
ZTJjYTIyOGE1NmM4OTAzYmMyZGU1ZDY4OGVhNzAzZWY4ZDMyYzA0NjgwZDk1
|
11
|
+
YjkzNjg4OGVkN2UwNjBlYzAyMTdlZWNjYjRkZjk3NTkzMGZmNTU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDBjZWNiNDVlNzAxMzVhYzdmZjIwMWFkYmI1ZjA0NTljYjFhNGI3NzdhN2Qw
|
14
|
+
NjYyYzAyMTRjMGYyMDY4ZGM1YTY0MDRmMzM4ZjE0OGE0Y2NhZWY4MGUyMTA3
|
15
|
+
ODc3MmM3NzJiZTA0NzJiMWFmNDMzZmMyMTJjN2JhYWNhM2I1MDg=
|
data/README.md
CHANGED
@@ -117,6 +117,23 @@ Once you're done, close the connection.
|
|
117
117
|
gibson.close
|
118
118
|
```
|
119
119
|
|
120
|
+
Usage with Rails 3.x and 4.x
|
121
|
+
---------------------------
|
122
|
+
|
123
|
+
In your Gemfile:
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
gem 'gibson'
|
127
|
+
```
|
128
|
+
|
129
|
+
In `config/environments/production.rb`:
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
config.cache_store = :gibson_store "namespace-of-your-app", { :socket => '/tmp/socket', :timeout => 50 }
|
133
|
+
```
|
134
|
+
|
135
|
+
Gibson does not support Rails 2.x.
|
136
|
+
|
120
137
|
License
|
121
138
|
---
|
122
139
|
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'active_support/core_ext/marshal'
|
2
|
+
require 'active_support/core_ext/string/conversions'
|
3
|
+
|
4
|
+
module ActiveSupport
|
5
|
+
module Cache
|
6
|
+
# A cache store implementation which stores everything on the Gibson cache server.
|
7
|
+
#
|
8
|
+
# GibsonStore implements the Strategy::LocalCache strategy which implements
|
9
|
+
# an in-memory cache inside of a block.
|
10
|
+
class GibsonStore < Store
|
11
|
+
attr_reader :namespace
|
12
|
+
attr_reader :options
|
13
|
+
|
14
|
+
def initialize( namespace, options )
|
15
|
+
@options = options.dup
|
16
|
+
@namespace = namespace.to_s
|
17
|
+
@gibson = Gibson::Client.new @options
|
18
|
+
|
19
|
+
extend Strategy::LocalCache
|
20
|
+
end
|
21
|
+
|
22
|
+
# Deletes all items from the cache.
|
23
|
+
def clear(options = nil)
|
24
|
+
@gibson.mdel @namespace + "::"
|
25
|
+
end
|
26
|
+
|
27
|
+
# Increments an already existing integer value that is stored in the cache.
|
28
|
+
def increment(name, amount = 1, options = nil)
|
29
|
+
key = expand_key(name)
|
30
|
+
amount.times do |v|
|
31
|
+
@gibson.inc key
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Decrements an already existing integer value that is stored in the cache.
|
36
|
+
def decrement(name, amount = 1, options = nil)
|
37
|
+
key = expand_key(name)
|
38
|
+
amount.times do |v|
|
39
|
+
@gibson.dec key
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Deletes multiple values by expression
|
44
|
+
def delete_matched(matcher, options = nil)
|
45
|
+
key = expand_key(matcher)
|
46
|
+
@gibson.mdel key
|
47
|
+
end
|
48
|
+
|
49
|
+
# Returns some stats
|
50
|
+
def stats
|
51
|
+
@gibson.stats
|
52
|
+
end
|
53
|
+
|
54
|
+
protected
|
55
|
+
|
56
|
+
def read_entry(key, options)
|
57
|
+
key = expand_key(key)
|
58
|
+
|
59
|
+
begin
|
60
|
+
cached = @gibson.get key
|
61
|
+
|
62
|
+
Marshal.load(cached)
|
63
|
+
rescue Gibson::NotFoundError
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def write_entry(key, entry, options)
|
69
|
+
e = Marshal.dump(entry)
|
70
|
+
|
71
|
+
key = expand_key(key)
|
72
|
+
|
73
|
+
begin
|
74
|
+
@gibson.set( options[:expires_in].to_i, key, e )
|
75
|
+
|
76
|
+
true
|
77
|
+
rescue
|
78
|
+
false
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def delete_entry(key, options)
|
83
|
+
key = expand_key(key)
|
84
|
+
|
85
|
+
begin
|
86
|
+
@gibson.del key
|
87
|
+
|
88
|
+
true
|
89
|
+
rescue
|
90
|
+
false
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def expand_key(v)
|
97
|
+
@namespace + "::" + v.to_s.tr( ' ', '_' )
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/lib/gibson/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gibson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simone Margaritelli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -30,6 +30,7 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
|
+
- lib/active_support/cache/gibson_store.rb
|
33
34
|
- lib/gibson/connection.rb
|
34
35
|
- lib/gibson/gibson.rb
|
35
36
|
- lib/gibson/protocol.rb
|