cachetastic 3.5.3 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +2 -1
- data/Gemfile.lock +3 -1
- data/lib/cachetastic.rb +5 -0
- data/lib/cachetastic/adapters/dalli.rb +84 -0
- data/lib/cachetastic/adapters/file.rb +1 -1
- data/lib/cachetastic/adapters/memcached.rb +7 -11
- data/lib/cachetastic/adapters/redis.rb +1 -1
- data/lib/cachetastic/cache.rb +2 -1
- data/lib/cachetastic/version.rb +1 -1
- data/spec/cachetastic/adapters/base_spec.rb +2 -2
- metadata +3 -2
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cachetastic (3.
|
4
|
+
cachetastic (3.6.0)
|
5
5
|
activesupport
|
6
6
|
configatron
|
7
7
|
|
@@ -13,6 +13,7 @@ GEM
|
|
13
13
|
multi_json (~> 1.0)
|
14
14
|
configatron (2.9.1)
|
15
15
|
yamler (>= 0.1.0)
|
16
|
+
dalli (2.6.0)
|
16
17
|
diff-lcs (1.1.3)
|
17
18
|
i18n (0.6.1)
|
18
19
|
memcache-client (1.8.5)
|
@@ -35,6 +36,7 @@ PLATFORMS
|
|
35
36
|
|
36
37
|
DEPENDENCIES
|
37
38
|
cachetastic!
|
39
|
+
dalli
|
38
40
|
memcache-client
|
39
41
|
rake
|
40
42
|
redis
|
data/lib/cachetastic.rb
CHANGED
@@ -9,6 +9,11 @@ begin
|
|
9
9
|
rescue Exception => e
|
10
10
|
puts "Memcached support is unavailable. To use Memcached do `gem install memcache-client`"
|
11
11
|
end
|
12
|
+
begin
|
13
|
+
require 'dalli'
|
14
|
+
rescue Exception => e
|
15
|
+
puts "Memcached (via Dalli) support is unavailable. To use Memcached (via Dalli) do `gem install dalli`"
|
16
|
+
end
|
12
17
|
begin
|
13
18
|
require 'redis'
|
14
19
|
rescue Exception => e
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Cachetastic # :nodoc:
|
2
|
+
module Adapters
|
3
|
+
class Dalli < Cachetastic::Adapters::Base
|
4
|
+
|
5
|
+
def initialize(klass) # :nodoc:
|
6
|
+
define_accessor(:dalli_servers)
|
7
|
+
define_accessor(:dalli_options)
|
8
|
+
define_accessor(:dalli_username)
|
9
|
+
define_accessor(:dalli_password)
|
10
|
+
self.dalli_servers = ['127.0.0.1:11211']
|
11
|
+
self.dalli_options = {}
|
12
|
+
super
|
13
|
+
connection
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(key) # :nodoc:
|
17
|
+
connection.get(transform_key(key), false)
|
18
|
+
end # get
|
19
|
+
|
20
|
+
def set(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry) # :nodoc:
|
21
|
+
connection.set(transform_key(key), marshal(value), expiry_time, false)
|
22
|
+
end # set
|
23
|
+
|
24
|
+
def delete(key) # :nodoc:
|
25
|
+
connection.delete(transform_key(key))
|
26
|
+
end # delete
|
27
|
+
|
28
|
+
def expire_all # :nodoc:
|
29
|
+
increment_version
|
30
|
+
@_mc_connection = nil
|
31
|
+
return nil
|
32
|
+
end # expire_all
|
33
|
+
|
34
|
+
def transform_key(key) # :nodoc:
|
35
|
+
key.to_s.hexdigest
|
36
|
+
end
|
37
|
+
|
38
|
+
# Return <tt>false</tt> if the connection to Memcached is
|
39
|
+
# either <tt>nil</tt> or not active.
|
40
|
+
def valid?
|
41
|
+
return false if @_mc_connection.nil?
|
42
|
+
return false unless @_mc_connection.stats
|
43
|
+
return true
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
def connection
|
48
|
+
unless @_mc_connection && valid? && @_ns_version == get_version
|
49
|
+
@_mc_connection = ::Dalli::Client.new(self.dalli_servers, self.dalli_options.merge(namespace: namespace))
|
50
|
+
end
|
51
|
+
@_mc_connection
|
52
|
+
end
|
53
|
+
|
54
|
+
def ns_connection
|
55
|
+
if !@_ns_connection || !@_ns_connection.stats
|
56
|
+
@_ns_connection = ::Dalli::Client.new(self.dalli_servers, self.dalli_options.merge(namespace: :namespace_versions))
|
57
|
+
end
|
58
|
+
@_ns_connection
|
59
|
+
end
|
60
|
+
|
61
|
+
def increment_version
|
62
|
+
name = self.klass.name
|
63
|
+
v = get_version
|
64
|
+
ns_connection.set(name, v + Time.now.to_i)
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_version
|
68
|
+
name = self.klass.name
|
69
|
+
v = ns_connection.get(name)
|
70
|
+
if v.nil?
|
71
|
+
v = Time.now.to_i
|
72
|
+
ns_connection.set(name, v)
|
73
|
+
end
|
74
|
+
v.to_i
|
75
|
+
end
|
76
|
+
|
77
|
+
def namespace
|
78
|
+
@_ns_version = get_version
|
79
|
+
"#{self.klass.name}.#{@_ns_version}"
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -31,7 +31,7 @@ module Cachetastic # :nodoc:
|
|
31
31
|
end # get
|
32
32
|
|
33
33
|
def set(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry) # :nodoc:
|
34
|
-
so = Cachetastic::Cache::StoreObject.new(key, value, expiry_time.from_now)
|
34
|
+
so = Cachetastic::Cache::StoreObject.new(key, unmarshal(value), expiry_time.from_now)
|
35
35
|
path = file_path(key)
|
36
36
|
::File.open(path, 'w') {|f| f.write marshal(so)}
|
37
37
|
value
|
@@ -5,7 +5,7 @@ module Cachetastic # :nodoc:
|
|
5
5
|
# This adapter supports the following configuration settings,
|
6
6
|
# in addition to the default settings:
|
7
7
|
#
|
8
|
-
# configatron.cachetastic.defaults.
|
8
|
+
# configatron.cachetastic.defaults.mc_servers = ['127.0.0.1:11211']
|
9
9
|
# configatron.cachetastic.defaults.mc_options = {c_threshold: 10_000,
|
10
10
|
# compression: true,
|
11
11
|
# debug: false,
|
@@ -13,8 +13,8 @@ module Cachetastic # :nodoc:
|
|
13
13
|
# urlencode: false}
|
14
14
|
# configatron.cachetastic.delete_delay = 0
|
15
15
|
#
|
16
|
-
# The <tt>
|
17
|
-
#
|
16
|
+
# The <tt>mc_servers</tt> setting defines an <tt>Array</tt> of Memcached
|
17
|
+
# mc_servers, represented as "<host>:<port>".
|
18
18
|
#
|
19
19
|
# The <tt>mc_options</tt> setting is a <tt>Hash</tt> of settings required
|
20
20
|
# by Memcached. See the Memcached documentation for more information on
|
@@ -28,16 +28,12 @@ module Cachetastic # :nodoc:
|
|
28
28
|
# methods.
|
29
29
|
class Memcached < Cachetastic::Adapters::Base
|
30
30
|
|
31
|
-
attr_accessor :servers
|
32
|
-
attr_accessor :mc_options
|
33
|
-
attr_accessor :delete_delay
|
34
|
-
|
35
31
|
def initialize(klass) # :nodoc:
|
36
|
-
define_accessor(:
|
32
|
+
define_accessor(:mc_servers)
|
37
33
|
define_accessor(:mc_options)
|
38
34
|
define_accessor(:delete_delay)
|
39
35
|
self.delete_delay = 0
|
40
|
-
self.
|
36
|
+
self.mc_servers = ['127.0.0.1:11211']
|
41
37
|
self.mc_options = {
|
42
38
|
c_threshold: 10_000,
|
43
39
|
compression: true,
|
@@ -82,14 +78,14 @@ module Cachetastic # :nodoc:
|
|
82
78
|
private
|
83
79
|
def connection
|
84
80
|
unless @_mc_connection && valid? && @_ns_version == get_version
|
85
|
-
@_mc_connection = MemCache.new(self.
|
81
|
+
@_mc_connection = MemCache.new(self.mc_servers, self.mc_options.merge(namespace: namespace))
|
86
82
|
end
|
87
83
|
@_mc_connection
|
88
84
|
end
|
89
85
|
|
90
86
|
def ns_connection
|
91
87
|
if !@_ns_connection || !@_ns_connection.active?
|
92
|
-
@_ns_connection = MemCache.new(self.
|
88
|
+
@_ns_connection = MemCache.new(self.mc_servers, self.mc_options.merge(namespace: :namespace_versions))
|
93
89
|
end
|
94
90
|
@_ns_connection
|
95
91
|
end
|
@@ -26,7 +26,7 @@ module Cachetastic
|
|
26
26
|
end # get
|
27
27
|
|
28
28
|
def set(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry) # :nodoc:
|
29
|
-
connection.setex(transform_key(key), expiry_time,
|
29
|
+
connection.setex(transform_key(key), expiry_time, value)
|
30
30
|
return value
|
31
31
|
end # set
|
32
32
|
|
data/lib/cachetastic/cache.rb
CHANGED
@@ -72,7 +72,7 @@ module Cachetastic # :nodoc:
|
|
72
72
|
def set(key, value, expiry_time = nil)
|
73
73
|
do_with_logging(:set, key) do
|
74
74
|
retryable do
|
75
|
-
self.adapter.set(key, value, calculate_expiry_time(expiry_time))
|
75
|
+
self.adapter.set(key, adapter.marshal(value), calculate_expiry_time(expiry_time))
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end # set
|
@@ -174,6 +174,7 @@ module Cachetastic # :nodoc:
|
|
174
174
|
end_time = Time.now
|
175
175
|
str = ''
|
176
176
|
unless res.nil?
|
177
|
+
res = adapter.unmarshal(res)
|
177
178
|
str = "[#{res.class.name}]"
|
178
179
|
str << "\t[Size = #{res.size}]" if res.respond_to? :size
|
179
180
|
str << "\t" << res.inspect
|
data/lib/cachetastic/version.rb
CHANGED
@@ -89,7 +89,7 @@ describe Cachetastic::Adapters do
|
|
89
89
|
|
90
90
|
end
|
91
91
|
|
92
|
-
['LocalMemory', 'File', 'Memcached', 'Redis'].each do |adapter|
|
92
|
+
['LocalMemory', 'File', 'Memcached', 'Redis', 'Dalli'].each do |adapter|
|
93
93
|
|
94
94
|
describe "#{adapter} (Common)" do
|
95
95
|
|
@@ -151,7 +151,7 @@ describe Cachetastic::Adapters do
|
|
151
151
|
CarCache.get(:bmw).should_not be_nil
|
152
152
|
end
|
153
153
|
|
154
|
-
unless ["Memcached", "Redis"].include?(adapter)
|
154
|
+
unless ["Memcached", "Redis", "Dalli"].include?(adapter)
|
155
155
|
it 'should set an object into the cache with an expiry' do
|
156
156
|
CarCache.get(:bmw).should be_nil
|
157
157
|
CarCache.set(:bmw, 'Beamer!', 1)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cachetastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- cachetastic.gemspec
|
76
76
|
- lib/cachetastic.rb
|
77
77
|
- lib/cachetastic/adapters/base.rb
|
78
|
+
- lib/cachetastic/adapters/dalli.rb
|
78
79
|
- lib/cachetastic/adapters/file.rb
|
79
80
|
- lib/cachetastic/adapters/local_memory.rb
|
80
81
|
- lib/cachetastic/adapters/memcached.rb
|