catch_cache 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: 662566bebd0e5976fabadbd420e8232dc6d59fb1
4
- data.tar.gz: d41e1ac4a87b44583b1600d3626785847bfe3c27
3
+ metadata.gz: aeae0742dd77cb93265bcae77e32f4d06154ab8e
4
+ data.tar.gz: 07f73a137ef2cc8e22a55a592433de21a83cc5f1
5
5
  SHA512:
6
- metadata.gz: 8adfa928da3c75f48c3f59d22fecf7c9f3efe369d3446a5c9c7c4974b8264a0166b917c1e61ab827db9a696b16ef7dee856ff5e3f618491047dfa009226f19ef
7
- data.tar.gz: 192116052ba1636f97f6fccb46044c376cf9edaba122e95f7be1f49e13edf8dbecf080a624e1fe74f801f8785392478893786e52d279c8029db99cd71d8c1590
6
+ metadata.gz: 67d510501ed20347dedb766b581ffc94313a0c70dd723891b27121598c2f5afa16607e273e3a4d097c55f7f889076d04531b1c3d17d009e2327a7ec97094380c
7
+ data.tar.gz: c22cf4f5ce38cd65f555195f8a12993897f2a299f7756ccd0b25f54927e9e2e54785c4bbe12f40bc843e0905ac1f4ffd380ed15e6c6232e0add916070b0e14a7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.0.3
2
+
3
+ - `catch_then_cache` method must be available as an instance method as well
4
+
1
5
  # 0.0.2
2
6
 
3
7
  - Swallow errors when calling the `key_callbacks` proc in `:flush_cache!`
@@ -18,6 +18,22 @@ module CatchCache
18
18
 
19
19
  cache
20
20
  end
21
+
22
+ def catch_then_cache(redis_key, &block)
23
+ redis = Redis.new
24
+ val = redis.get(redis_key)
25
+
26
+ # retrieve the cache with redis_key as its key
27
+ cache = JSON.parse(val.blank? ? "[]" : val)
28
+
29
+ if cache.blank?
30
+ timeline_logs = block.call
31
+ redis.set(redis_key, timeline_logs.to_json)
32
+ cache = JSON.parse(redis.get(redis_key))
33
+ end
34
+
35
+ cache
36
+ end
21
37
  end
22
38
  end
23
39
  end
@@ -1,3 +1,3 @@
1
1
  module CatchCache
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catch_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil Marion dela Cruz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-11 00:00:00.000000000 Z
11
+ date: 2017-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis