local_cache 1.2.0 → 1.2.1
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/lib/local_cache.rb +11 -12
- data/test/local_cache_tests.rb +14 -0
- metadata +4 -4
data/lib/local_cache.rb
CHANGED
@@ -18,7 +18,7 @@ class LocalCache < ActiveSupport::Cache::Store
|
|
18
18
|
@cache_list = []
|
19
19
|
end
|
20
20
|
|
21
|
-
def get(key)
|
21
|
+
def get(key, options={})
|
22
22
|
# if the API URL exists as a key in cache, we just return it
|
23
23
|
# we also make sure the data is fresh
|
24
24
|
#puts 'looking in cache for: ' + key.to_s
|
@@ -39,7 +39,7 @@ class LocalCache < ActiveSupport::Cache::Store
|
|
39
39
|
return nil
|
40
40
|
end
|
41
41
|
|
42
|
-
def get_multi(keys,
|
42
|
+
def get_multi(keys, options={})
|
43
43
|
ret = {}
|
44
44
|
keys.each do |k|
|
45
45
|
val = get(k)
|
@@ -68,9 +68,8 @@ class LocalCache < ActiveSupport::Cache::Store
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
def put(key, val,
|
72
|
-
seconds_to_store =
|
73
|
-
#puts 'seconds=' + seconds_to_store.to_s
|
71
|
+
def put(key, val, options={})
|
72
|
+
seconds_to_store = options[:expires_in] || options[:ttl] || @default_expires_in
|
74
73
|
@cache[key] = [Time.now+seconds_to_store, val]
|
75
74
|
@cache_list << key
|
76
75
|
while @cache.size > @size && @cache_list.size > 0
|
@@ -79,26 +78,26 @@ class LocalCache < ActiveSupport::Cache::Store
|
|
79
78
|
end
|
80
79
|
end
|
81
80
|
|
82
|
-
def read(name, options
|
81
|
+
def read(name, options={})
|
83
82
|
# puts 'read from localcache'
|
84
83
|
super
|
85
|
-
ret = get(name)
|
84
|
+
ret = get(name, options)
|
86
85
|
# puts 'ret.frozen=' + ret.frozen?.to_s
|
87
86
|
return ret
|
88
87
|
end
|
89
88
|
|
90
|
-
def write(name, value, options
|
89
|
+
def write(name, value, options={})
|
91
90
|
super
|
92
|
-
put(name, value, options
|
91
|
+
put(name, value, options)
|
93
92
|
# puts 'write.frozen=' + value.frozen?.to_s
|
94
93
|
end
|
95
94
|
|
96
|
-
def delete(name, options
|
95
|
+
def delete(name, options={})
|
97
96
|
super
|
98
97
|
@cache.delete(name)
|
99
98
|
end
|
100
99
|
|
101
|
-
def delete_matched(matcher, options
|
100
|
+
def delete_matched(matcher, options={})
|
102
101
|
super
|
103
102
|
raise "delete_matched not supported by LocalCache"
|
104
103
|
end
|
@@ -111,4 +110,4 @@ module ActiveSupport
|
|
111
110
|
class LocalCache < ::LocalCache
|
112
111
|
end
|
113
112
|
end
|
114
|
-
end
|
113
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.join(File.dirname(__FILE__), "../lib/local_cache")
|
3
|
+
|
4
|
+
class LocalCacheTests < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_put_get
|
7
|
+
|
8
|
+
cache = ActiveSupport::Cache::LocalCache.new
|
9
|
+
cache.write("tk", "somethign")
|
10
|
+
puts 'read=' + cache.read("tk").inspect
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: local_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Reeder
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-20 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -52,5 +52,5 @@ rubygems_version: 1.3.5
|
|
52
52
|
signing_key:
|
53
53
|
specification_version: 3
|
54
54
|
summary: Similar to Rails' built in MemoryStore, but adds size limit and expiration.
|
55
|
-
test_files:
|
56
|
-
|
55
|
+
test_files:
|
56
|
+
- test/local_cache_tests.rb
|