zache 0.10.1 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zache.rb +12 -10
- data/test/test_zache.rb +1 -0
- data/zache.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4686166302287dae583252d66cd7d1a265a9fea6f5cc6c68f321249a9fe04d5e
|
4
|
+
data.tar.gz: 7d960c4c23fa027e623f033a3ba618802d43d6d65a8b863c1ce99eb297fdacff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef2ef6578ec02be0572e92f1e45ff104f9039bb3b189c5f2647c80d69a0c8f82a27bdd2f3238770b09c877b2424ace681b59f232713c6457cec07cf716ea85bf
|
7
|
+
data.tar.gz: f1651dd070af026762a57f2a1b34f45cceae1bac625a4b0bd5c32f1492615cf4e54f12fddaa8d50f19f84679b7d2096285670b839b79d190b50844531a865b8b
|
data/lib/zache.rb
CHANGED
@@ -96,13 +96,13 @@ class Zache
|
|
96
96
|
# calculated result will be returned if it exists and is already expired.
|
97
97
|
def get(key, lifetime: 2**32, dirty: false)
|
98
98
|
if block_given?
|
99
|
-
if (dirty || @dirty) && locked? &&
|
99
|
+
if (dirty || @dirty) && locked? && expired?(key) && @hash.key?(key)
|
100
100
|
return @hash[key][:value]
|
101
101
|
end
|
102
102
|
synchronized { calc(key, lifetime) { yield } }
|
103
103
|
else
|
104
104
|
rec = @hash[key]
|
105
|
-
if
|
105
|
+
if expired?(key)
|
106
106
|
return rec[:value] if dirty || @dirty
|
107
107
|
@hash.delete(key)
|
108
108
|
rec = nil
|
@@ -117,13 +117,20 @@ class Zache
|
|
117
117
|
# it will be removed by this method and the result will be FALSE.
|
118
118
|
def exists?(key, dirty: false)
|
119
119
|
rec = @hash[key]
|
120
|
-
if
|
120
|
+
if expired?(key) && !dirty && !@dirty
|
121
121
|
@hash.delete(key)
|
122
122
|
rec = nil
|
123
123
|
end
|
124
124
|
!rec.nil?
|
125
125
|
end
|
126
126
|
|
127
|
+
# Checks whether the key exists in the cache and is expired. If the
|
128
|
+
# key is absent FALSE is returned.
|
129
|
+
def expired?(key)
|
130
|
+
rec = @hash[key]
|
131
|
+
!rec.nil? && rec[:start] < Time.now - rec[:lifetime]
|
132
|
+
end
|
133
|
+
|
127
134
|
# Returns the modification time of the key, if it exists.
|
128
135
|
# If not, current time is returned.
|
129
136
|
def mtime(key)
|
@@ -160,14 +167,14 @@ class Zache
|
|
160
167
|
|
161
168
|
# Remove keys that are expired.
|
162
169
|
def clean
|
163
|
-
synchronized { @hash.delete_if { |_key, value|
|
170
|
+
synchronized { @hash.delete_if { |_key, value| expired?(value) } }
|
164
171
|
end
|
165
172
|
|
166
173
|
private
|
167
174
|
|
168
175
|
def calc(key, lifetime)
|
169
176
|
rec = @hash[key]
|
170
|
-
rec = nil if
|
177
|
+
rec = nil if expired?(key)
|
171
178
|
if rec.nil?
|
172
179
|
@hash[key] = {
|
173
180
|
value: yield,
|
@@ -191,9 +198,4 @@ class Zache
|
|
191
198
|
yield
|
192
199
|
end
|
193
200
|
end
|
194
|
-
|
195
|
-
def key_expired?(key)
|
196
|
-
rec = @hash[key]
|
197
|
-
!rec.nil? && rec[:start] < Time.now - rec[:lifetime]
|
198
|
-
end
|
199
201
|
end
|
data/test/test_zache.rb
CHANGED
data/zache.gemspec
CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.rubygems_version = '2.5'
|
32
32
|
s.required_ruby_version = '>=2.5'
|
33
33
|
s.name = 'zache'
|
34
|
-
s.version = '0.
|
34
|
+
s.version = '0.11.0'
|
35
35
|
s.license = 'MIT'
|
36
36
|
s.summary = 'In-memory Cache'
|
37
37
|
s.description = 'Zero-footprint in-memory thread-safe cache'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|