markbates-cachetastic-three 2.9.9.20090525090948 → 2.9.9.20090605145500
Sign up to get free protection for your applications and to get access to all the features.
@@ -73,23 +73,6 @@ module Cachetastic
|
|
73
73
|
end
|
74
74
|
|
75
75
|
private
|
76
|
-
# If the expiry time is set to 60 minutes and the expiry_swing time is set to
|
77
|
-
# 15 minutes, this method will return a number between 45 minutes and 75 minutes.
|
78
|
-
def calculate_expiry_time(expiry_time) # :doc:
|
79
|
-
expiry_time = self.default_expiry if expiry_time.nil?
|
80
|
-
exp_swing = self.expiry_swing
|
81
|
-
if exp_swing && exp_swing != 0
|
82
|
-
swing = rand(exp_swing.to_i)
|
83
|
-
case rand(2)
|
84
|
-
when 0
|
85
|
-
expiry_time = (expiry_time.to_i + swing)
|
86
|
-
when 1
|
87
|
-
expiry_time = (expiry_time.to_i - swing)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
expiry_time
|
91
|
-
end
|
92
|
-
|
93
76
|
def define_accessor(key)
|
94
77
|
instance_eval(%{
|
95
78
|
def #{key}
|
@@ -17,8 +17,8 @@ module Cachetastic
|
|
17
17
|
return val
|
18
18
|
end # get
|
19
19
|
|
20
|
-
def set(key, value, expiry_time =
|
21
|
-
so = Cachetastic::Cache::StoreObject.new(key, value,
|
20
|
+
def set(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry)
|
21
|
+
so = Cachetastic::Cache::StoreObject.new(key, value, expiry_time.from_now)
|
22
22
|
path = file_path(key)
|
23
23
|
::File.open(path, 'w') {|f| f.write marshal(so)}
|
24
24
|
value
|
@@ -11,8 +11,8 @@ module Cachetastic
|
|
11
11
|
@_store[key]
|
12
12
|
end # get
|
13
13
|
|
14
|
-
def set(key, value, expiry_time =
|
15
|
-
so = Cachetastic::Cache::StoreObject.new(key, value,
|
14
|
+
def set(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry)
|
15
|
+
so = Cachetastic::Cache::StoreObject.new(key, value, expiry_time.from_now)
|
16
16
|
@_store[key] = marshal(so)
|
17
17
|
value
|
18
18
|
end # set
|
@@ -22,8 +22,8 @@ module Cachetastic
|
|
22
22
|
connection.get(transform_key(key), false)
|
23
23
|
end # get
|
24
24
|
|
25
|
-
def set(key, value, expiry_time =
|
26
|
-
connection.set(transform_key(key), marshal(value),
|
25
|
+
def set(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry)
|
26
|
+
connection.set(transform_key(key), marshal(value), expiry_time, false)
|
27
27
|
end # set
|
28
28
|
|
29
29
|
def delete(key)
|
@@ -84,10 +84,4 @@ module Cachetastic
|
|
84
84
|
|
85
85
|
end # Memcached
|
86
86
|
end # Adapters
|
87
|
-
end # Cachetastic
|
88
|
-
|
89
|
-
# c_threshold: 10_000
|
90
|
-
# compression: true
|
91
|
-
# debug: false
|
92
|
-
# readonly: false
|
93
|
-
# urlencode: false
|
87
|
+
end # Cachetastic
|
data/lib/cachetastic/cache.rb
CHANGED
@@ -12,7 +12,7 @@ module Cachetastic
|
|
12
12
|
|
13
13
|
def set(key, value, expiry_time = nil)
|
14
14
|
do_with_logging(:set, key) do
|
15
|
-
self.adapter.set(key, value, expiry_time)
|
15
|
+
self.adapter.set(key, value, calculate_expiry_time(expiry_time))
|
16
16
|
end
|
17
17
|
end # set
|
18
18
|
|
@@ -53,6 +53,23 @@ module Cachetastic
|
|
53
53
|
end
|
54
54
|
|
55
55
|
private
|
56
|
+
# If the expiry time is set to 60 minutes and the expiry_swing time is set to
|
57
|
+
# 15 minutes, this method will return a number between 45 minutes and 75 minutes.
|
58
|
+
def calculate_expiry_time(expiry_time) # :doc:
|
59
|
+
expiry_time = self.adapter.default_expiry if expiry_time.nil?
|
60
|
+
exp_swing = self.adapter.expiry_swing
|
61
|
+
if exp_swing && exp_swing != 0
|
62
|
+
swing = rand(exp_swing.to_i)
|
63
|
+
case rand(2)
|
64
|
+
when 0
|
65
|
+
expiry_time = (expiry_time.to_i + swing)
|
66
|
+
when 1
|
67
|
+
expiry_time = (expiry_time.to_i - swing)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
expiry_time
|
71
|
+
end
|
72
|
+
|
56
73
|
def handle_store_object(key, val, &block)
|
57
74
|
if val.is_a?(Cachetastic::Cache::StoreObject)
|
58
75
|
if val.expired?
|
@@ -87,7 +87,7 @@ module Cachetastic
|
|
87
87
|
# Person.cacher("say_hi") {"Hi There"} # => "Hi There"
|
88
88
|
# Person.get_from_cache("say_hi") # => "Hi There"
|
89
89
|
# Cachetastic::Cacheable::PersonCache.get("say_hi") # => "Hi There"
|
90
|
-
def cacher(key, expiry =
|
90
|
+
def cacher(key, expiry = nil)
|
91
91
|
cache_class.get(key) do
|
92
92
|
if block_given?
|
93
93
|
res = yield
|
@@ -118,6 +118,7 @@ module Cachetastic
|
|
118
118
|
def expire_all
|
119
119
|
cache_class.expire_all
|
120
120
|
end
|
121
|
+
|
121
122
|
end
|
122
123
|
|
123
124
|
# --------------------------
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: markbates-cachetastic-three
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.9.9.
|
4
|
+
version: 2.9.9.20090605145500
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Bates
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05
|
12
|
+
date: 2009-06-05 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|