simple_cache_rs 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.2
1
+ 0.9.3
data/lib/simple_cache.rb CHANGED
@@ -25,19 +25,23 @@ module SimpleCache
25
25
  singleton_class.class_eval do
26
26
  attr :url, true
27
27
 
28
+ def url
29
+ @url || raise(ArgumentError, "Missing 'SimpleCache.url' setting.")
30
+ end
31
+
28
32
  def cache_store
29
33
  Thread.current["simple_cache_store"] ||= new(url)
30
34
  end
31
- end
32
35
 
33
- singleton_class.class_eval do
34
36
  extend Forwardable
35
- delegate [:fetch, :store, :cached, :clear] => :cache_store
37
+ delegate [:fetch, :store, :clear, :cached] => :cache_store
36
38
  end
37
-
39
+
38
40
  def cached(key, ttl = nil, &block)
39
41
  fetch(key) do
40
- store(key, yield, ttl)
42
+ value = yield
43
+ store(key, value, ttl) unless ttl == 0 || ttl == false
44
+ value
41
45
  end
42
46
  end
43
47
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "simple_cache_rs"
8
- s.version = "0.9.2"
8
+ s.version = "0.9.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["radiospiel"]
12
- s.date = "2012-04-09"
12
+ s.date = "2012-05-03"
13
13
  s.description = "A sensibly fast, yet simplistic file based cache."
14
14
  s.email = "eno@open-lab.org"
15
15
  s.extra_rdoc_files = [
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  "simple_cache.gemspec",
32
32
  "simple_cache_rs.gemspec",
33
33
  "test/redis_store_test.rb",
34
+ "test/simple_cache_test.rb",
34
35
  "test/sqlite_store_test.rb",
35
36
  "test/test_helper.rb"
36
37
  ]
@@ -0,0 +1,22 @@
1
+ require_relative 'test_helper'
2
+
3
+ class SimpleCacheTest < Test::Unit::TestCase
4
+ def test_simple_cache
5
+ SimpleCache.url = "simple_cache_gem"
6
+ SimpleCache.cache_store.clear
7
+
8
+ assert_equal(nil, SimpleCache.fetch("bar"))
9
+
10
+ assert_equal("foo", SimpleCache.store("bar", "foo"))
11
+ assert_equal("foo", SimpleCache.fetch("bar"))
12
+
13
+ done = 0
14
+ assert_equal "baz", SimpleCache.cached("key") { done += 1; "baz" }
15
+ assert_equal 1, done
16
+ assert_equal "baz", SimpleCache.cached("key") { done += 1; "baz" }
17
+ assert_equal 1, done
18
+
19
+ assert_equal(nil, SimpleCache.store("bar", nil))
20
+ assert_equal(nil, SimpleCache.fetch("bar"))
21
+ end
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_cache_rs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-09 00:00:00.000000000 Z
12
+ date: 2012-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sqlite3
16
- requirement: &70334088972580 !ruby/object:Gem::Requirement
16
+ requirement: &70161923648460 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70334088972580
24
+ version_requirements: *70161923648460
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &70334088972000 !ruby/object:Gem::Requirement
27
+ requirement: &70161923647820 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70334088972000
35
+ version_requirements: *70161923647820
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jeweler
38
- requirement: &70334088971220 !ruby/object:Gem::Requirement
38
+ requirement: &70161923640800 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70334088971220
46
+ version_requirements: *70161923640800
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: simplecov
49
- requirement: &70334088970660 !ruby/object:Gem::Requirement
49
+ requirement: &70161923639800 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70334088970660
57
+ version_requirements: *70161923639800
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: ruby-debug19
60
- requirement: &70334088970060 !ruby/object:Gem::Requirement
60
+ requirement: &70161923638540 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70334088970060
68
+ version_requirements: *70161923638540
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: timecop
71
- requirement: &70334088969540 !ruby/object:Gem::Requirement
71
+ requirement: &70161923634620 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70334088969540
79
+ version_requirements: *70161923634620
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: redis
82
- requirement: &70334088968200 !ruby/object:Gem::Requirement
82
+ requirement: &70161923633860 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70334088968200
90
+ version_requirements: *70161923633860
91
91
  description: A sensibly fast, yet simplistic file based cache.
92
92
  email: eno@open-lab.org
93
93
  executables: []
@@ -110,6 +110,7 @@ files:
110
110
  - simple_cache.gemspec
111
111
  - simple_cache_rs.gemspec
112
112
  - test/redis_store_test.rb
113
+ - test/simple_cache_test.rb
113
114
  - test/sqlite_store_test.rb
114
115
  - test/test_helper.rb
115
116
  homepage: http://github.com/radiospiel/simple_cache
@@ -127,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
128
  version: '0'
128
129
  segments:
129
130
  - 0
130
- hash: -1582995027855660094
131
+ hash: -4386423963111190464
131
132
  required_rubygems_version: !ruby/object:Gem::Requirement
132
133
  none: false
133
134
  requirements: