zache 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8dc4e7bf81e1fac197d586d7b9609133ba5de20c2183be9e49fc50e4ab018e0c
4
- data.tar.gz: f01851cba887991e6ae63b47070ed54ba373f1a15a57ea5d60a9fe4e7a7cf8b2
3
+ metadata.gz: 6c2af949ace2c9836128379aac9360bfc0aeff387e700b464f7c300ad3e1fea7
4
+ data.tar.gz: 4c4b7ddf99e30e27b012e8d98f9b102acff016e4ec6021953008bc8283f8f08f
5
5
  SHA512:
6
- metadata.gz: a5c2f5d7d5d08946c741ae8c48f9ad4b84992b4a151f5450dc15f44b7c44b67ba6448cab10b795638fe3e91192e3ac5decf587b9635c1ecb846e74546ef61c23
7
- data.tar.gz: 45f346fc252d1a44b25702165ecd35ddc2d18f4415625f9481187be0cb13282fbb57633f5168e0fc2d5c45976eeb949876582ffe42d2d5c43922823dfd27ed31
6
+ metadata.gz: 842ee794a1d2055bec22948417227b24d56fbe016c8828d16db01e75e61908895ae3ba71620fd5fca0ec1c7f8c28f99407ead492c486a64fa9f0e9478b07429c
7
+ data.tar.gz: 18a3c7f5af71e1edf227954391eb9265e1a4dd812480931841bf0ac47b6f77387814f749cb8bb3a98280fc724b83af188a5c13d6c16e19ef4cfc3118377dddde
@@ -123,6 +123,13 @@ class Zache
123
123
  !rec.nil?
124
124
  end
125
125
 
126
+ # Returns the modification time of the key, if it exists.
127
+ # If not, current time is returned.
128
+ def mtime(key)
129
+ rec = @hash[key]
130
+ rec.nil? ? Time.now : rec[:start]
131
+ end
132
+
126
133
  # Is cache currently locked doing something?
127
134
  def locked?
128
135
  @mutex.locked?
@@ -51,6 +51,13 @@ class ZacheTest < Minitest::Test
51
51
  assert(first != second)
52
52
  end
53
53
 
54
+ def test_calculates_age
55
+ cache = Zache.new
56
+ cache.get(:hey) { Random.rand }
57
+ sleep 0.1
58
+ assert(cache.mtime(:hey) < Time.now - 0.05)
59
+ end
60
+
54
61
  def test_caches_in_threads
55
62
  cache = Zache.new
56
63
  Threads.new(10).assert(100) do
@@ -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.8.0'
34
+ s.version = '0.9.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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko