cachy 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +9 -0
- data/Gemfile.lock +28 -0
- data/Rakefile +5 -3
- data/VERSION +1 -1
- data/cachy.gemspec +43 -30
- data/lib/cachy.rb +8 -15
- data/spec/cachy_spec.rb +6 -11
- metadata +74 -12
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.5.2)
|
7
|
+
bundler (~> 1.0.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
mini_memory_store (0.1.0)
|
11
|
+
rake (0.8.7)
|
12
|
+
rspec (2.3.0)
|
13
|
+
rspec-core (~> 2.3.0)
|
14
|
+
rspec-expectations (~> 2.3.0)
|
15
|
+
rspec-mocks (~> 2.3.0)
|
16
|
+
rspec-core (2.3.1)
|
17
|
+
rspec-expectations (2.3.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.3.0)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
jeweler
|
26
|
+
mini_memory_store
|
27
|
+
rake
|
28
|
+
rspec (~> 2)
|
data/Rakefile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
task :default => :spec
|
2
|
-
require
|
3
|
-
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
4
|
+
t.rspec_opts = '--backtrace --color'
|
5
|
+
end
|
4
6
|
|
5
7
|
begin
|
6
8
|
require 'jeweler'
|
@@ -16,4 +18,4 @@ begin
|
|
16
18
|
Jeweler::GemcutterTasks.new
|
17
19
|
rescue LoadError
|
18
20
|
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
19
|
-
end
|
21
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/cachy.gemspec
CHANGED
@@ -1,60 +1,73 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cachy}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Grosser"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-12-22}
|
13
13
|
s.email = %q{grosser.michael@gmail.com}
|
14
14
|
s.files = [
|
15
|
+
"Gemfile",
|
16
|
+
"Gemfile.lock",
|
15
17
|
"Rakefile",
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
18
|
+
"Readme.md",
|
19
|
+
"VERSION",
|
20
|
+
"cachy.gemspec",
|
21
|
+
"lib/cachy.rb",
|
22
|
+
"lib/cachy/memcache_timeout_protection.rb",
|
23
|
+
"lib/cachy/memcached_wrapper.rb",
|
24
|
+
"lib/cachy/moneta_wrapper.rb",
|
25
|
+
"lib/cachy/redis_wrapper.rb",
|
26
|
+
"lib/cachy/wrapper.rb",
|
27
|
+
"spec/cachy/memcache_timeout_protection_spec.rb",
|
28
|
+
"spec/cachy/memcached_wrapper_spec.rb",
|
29
|
+
"spec/cachy/moneta_wrapper_spec.rb",
|
30
|
+
"spec/cachy/redis_wrapper_spec.rb",
|
31
|
+
"spec/cachy_spec.rb",
|
32
|
+
"spec/mem_cache.rb",
|
33
|
+
"spec/spec_helper.rb",
|
34
|
+
"spec/test_cache.rb"
|
33
35
|
]
|
34
36
|
s.homepage = %q{http://github.com/grosser/cachy}
|
35
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
36
37
|
s.require_paths = ["lib"]
|
37
|
-
s.rubygems_version = %q{1.3.
|
38
|
+
s.rubygems_version = %q{1.3.7}
|
38
39
|
s.summary = %q{Caching library for projects that have many processes or many caches}
|
39
40
|
s.test_files = [
|
41
|
+
"spec/cachy/memcache_timeout_protection_spec.rb",
|
40
42
|
"spec/cachy/memcached_wrapper_spec.rb",
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
"spec/spec_helper.rb"
|
43
|
+
"spec/cachy/moneta_wrapper_spec.rb",
|
44
|
+
"spec/cachy/redis_wrapper_spec.rb",
|
45
|
+
"spec/cachy_spec.rb",
|
46
|
+
"spec/mem_cache.rb",
|
47
|
+
"spec/spec_helper.rb",
|
48
|
+
"spec/test_cache.rb"
|
48
49
|
]
|
49
50
|
|
50
51
|
if s.respond_to? :specification_version then
|
51
52
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
52
53
|
s.specification_version = 3
|
53
54
|
|
54
|
-
if Gem::Version.new(Gem::
|
55
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
|
+
s.add_runtime_dependency(%q<mini_memory_store>, [">= 0"])
|
57
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<rspec>, ["~> 2"])
|
59
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
55
60
|
else
|
61
|
+
s.add_dependency(%q<mini_memory_store>, [">= 0"])
|
62
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
63
|
+
s.add_dependency(%q<rspec>, ["~> 2"])
|
64
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
56
65
|
end
|
57
66
|
else
|
67
|
+
s.add_dependency(%q<mini_memory_store>, [">= 0"])
|
68
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
69
|
+
s.add_dependency(%q<rspec>, ["~> 2"])
|
70
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
58
71
|
end
|
59
72
|
end
|
60
73
|
|
data/lib/cachy.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'mini_memory_store'
|
2
|
+
|
1
3
|
class Cachy
|
2
4
|
WHILE_RUNNING_TIMEOUT = 5*60 #seconds
|
3
5
|
KEY_VERSION_TIMEOUT = 30 #seconds
|
@@ -78,19 +80,12 @@ class Cachy
|
|
78
80
|
expire(*args)
|
79
81
|
end
|
80
82
|
|
81
|
-
# Fetch key_versions from cache every KEY_VERSION_TIMEOUT seconds,
|
82
|
-
# otherwise every .key call would result in an cache request
|
83
|
-
@@key_versions = {:versions=>{}, :last_set=>0}
|
84
83
|
def self.key_versions
|
85
|
-
|
86
|
-
versions = read_versions
|
87
|
-
@@key_versions = {:versions=>versions, :last_set=>Time.now.to_i}
|
88
|
-
end
|
89
|
-
@@key_versions[:versions]
|
84
|
+
memory_store.cache{ read_versions }
|
90
85
|
end
|
91
86
|
|
92
87
|
def self.key_versions=(data)
|
93
|
-
|
88
|
+
memory_store.clear
|
94
89
|
write_version(data)
|
95
90
|
end
|
96
91
|
|
@@ -189,12 +184,6 @@ class Cachy
|
|
189
184
|
cache_store.read(HEALTH_CHECK_KEY) == 'yes'
|
190
185
|
end
|
191
186
|
|
192
|
-
# Do we need to fetch fresh key_versions from cache ?
|
193
|
-
def self.key_versions_expired?
|
194
|
-
key_versions_timeout = Time.now.to_i - KEY_VERSION_TIMEOUT
|
195
|
-
@@key_versions[:last_set] < key_versions_timeout
|
196
|
-
end
|
197
|
-
|
198
187
|
# Temorarily store something else in the cache,
|
199
188
|
# so that a often-called and slow cache-block is not run by
|
200
189
|
# multiple processes in parallel
|
@@ -249,6 +238,10 @@ class Cachy
|
|
249
238
|
{}
|
250
239
|
end
|
251
240
|
end
|
241
|
+
|
242
|
+
def self.memory_store
|
243
|
+
@memory_store ||= MiniMemoryStore.new(:expires_in => KEY_VERSION_TIMEOUT)
|
244
|
+
end
|
252
245
|
end
|
253
246
|
|
254
247
|
Cachy.cache_store = ActionController::Base.cache_store if defined? ActionController::Base
|
data/spec/cachy_spec.rb
CHANGED
@@ -4,9 +4,9 @@ describe Cachy do
|
|
4
4
|
before do
|
5
5
|
@cache = TestCache.new
|
6
6
|
Cachy.cache_store = @cache
|
7
|
-
Cachy.class_eval "@@key_versions = {:versions=>{}, :last_set=>0}"
|
8
7
|
@cache.write(Cachy::HEALTH_CHECK_KEY, 'yes')
|
9
8
|
Cachy.send(:class_variable_set, '@@cache_error', false)
|
9
|
+
Cachy.send(:memory_store).clear
|
10
10
|
end
|
11
11
|
|
12
12
|
describe :cache do
|
@@ -263,21 +263,16 @@ describe Cachy do
|
|
263
263
|
end
|
264
264
|
|
265
265
|
it "reloads when keys have expired" do
|
266
|
-
Cachy.
|
266
|
+
Cachy.key_versions.should == {} # fills cache
|
267
267
|
@cache.write Cachy::KEY_VERSIONS_KEY, {:xx=>1}
|
268
|
+
Cachy.send(:memory_store).clear
|
268
269
|
Cachy.key_versions.should == {:xx=>1}
|
269
270
|
end
|
270
271
|
|
271
|
-
it "does not reload when keys have not expired" do
|
272
|
-
Cachy.send :class_variable_set, "@@key_versions", {:versions=>{:xx=>2}, :last_set=>Time.now.to_i}
|
273
|
-
@cache.write Cachy::KEY_VERSIONS_KEY, {:xx=>1}
|
274
|
-
Cachy.key_versions.should == {:xx=>2}
|
275
|
-
end
|
276
|
-
|
277
272
|
it "expires when key_versions is set" do
|
278
|
-
Cachy.
|
279
|
-
Cachy.key_versions = {:xx=>1}
|
280
|
-
Cachy.key_versions
|
273
|
+
Cachy.key_versions.should == {}
|
274
|
+
Cachy.key_versions = {:xx => 1}
|
275
|
+
Cachy.key_versions.should == {:xx => 1}
|
281
276
|
end
|
282
277
|
end
|
283
278
|
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cachy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Michael Grosser
|
@@ -14,10 +15,65 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-12-22 00:00:00 +01:00
|
18
19
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
name: mini_memory_store
|
32
|
+
prerelease: false
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 3
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
name: rake
|
46
|
+
prerelease: false
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 7
|
56
|
+
segments:
|
57
|
+
- 2
|
58
|
+
version: "2"
|
59
|
+
name: rspec
|
60
|
+
prerelease: false
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
name: jeweler
|
74
|
+
prerelease: false
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
21
77
|
description:
|
22
78
|
email: grosser.michael@gmail.com
|
23
79
|
executables: []
|
@@ -27,6 +83,8 @@ extensions: []
|
|
27
83
|
extra_rdoc_files: []
|
28
84
|
|
29
85
|
files:
|
86
|
+
- Gemfile
|
87
|
+
- Gemfile.lock
|
30
88
|
- Rakefile
|
31
89
|
- Readme.md
|
32
90
|
- VERSION
|
@@ -50,37 +108,41 @@ homepage: http://github.com/grosser/cachy
|
|
50
108
|
licenses: []
|
51
109
|
|
52
110
|
post_install_message:
|
53
|
-
rdoc_options:
|
54
|
-
|
111
|
+
rdoc_options: []
|
112
|
+
|
55
113
|
require_paths:
|
56
114
|
- lib
|
57
115
|
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
58
117
|
requirements:
|
59
118
|
- - ">="
|
60
119
|
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
61
121
|
segments:
|
62
122
|
- 0
|
63
123
|
version: "0"
|
64
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
65
126
|
requirements:
|
66
127
|
- - ">="
|
67
128
|
- !ruby/object:Gem::Version
|
129
|
+
hash: 3
|
68
130
|
segments:
|
69
131
|
- 0
|
70
132
|
version: "0"
|
71
133
|
requirements: []
|
72
134
|
|
73
135
|
rubyforge_project:
|
74
|
-
rubygems_version: 1.3.
|
136
|
+
rubygems_version: 1.3.7
|
75
137
|
signing_key:
|
76
138
|
specification_version: 3
|
77
139
|
summary: Caching library for projects that have many processes or many caches
|
78
140
|
test_files:
|
141
|
+
- spec/cachy/memcache_timeout_protection_spec.rb
|
79
142
|
- spec/cachy/memcached_wrapper_spec.rb
|
80
143
|
- spec/cachy/moneta_wrapper_spec.rb
|
81
|
-
- spec/cachy/memcache_timeout_protection_spec.rb
|
82
144
|
- spec/cachy/redis_wrapper_spec.rb
|
83
|
-
- spec/mem_cache.rb
|
84
145
|
- spec/cachy_spec.rb
|
85
|
-
- spec/
|
146
|
+
- spec/mem_cache.rb
|
86
147
|
- spec/spec_helper.rb
|
148
|
+
- spec/test_cache.rb
|