greencache 0.1.2 → 0.2.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: 3dff03b6a7842d910edca9c0621c2d397db6f717e8047df76024b74af6bc6a72
4
- data.tar.gz: 24ce73bdfd300b5a99a05cbadd3d1df511a8e1272d18409eba3523ee965b6839
3
+ metadata.gz: 89089770b5bbd5abf1e5d6a52d170b86735de343c39255d5693a662e58b8e12b
4
+ data.tar.gz: 8190ba01e4aad4196ecfdcfe561523fe983b45bc6d6b7069dc5c61f1030c72c0
5
5
  SHA512:
6
- metadata.gz: 1067e72923725c96a23b22b6cb710ea177e0efeae3637c8e4ad321a9aebeb71729bc091515d96e60baa56f600ef57cc1cf69bf5c4a3bfd003ef85effeb8c4b09
7
- data.tar.gz: 8f2db04b23fccf1a756fb7f3ce4ed52e7c1d243d44c6d45200e49cae75df775a6b99fee6f0d3ae2cf4586f2c4923b78d9345d599296e79c04a39b4a5b0d4fa90
6
+ metadata.gz: da86d39a8c8c3c1c546d8e58919fa5cd29e2ca1ef9871f9652c46f4f007842782792de66caafa364298bf92be0ddd69536979e141f289469f06c4625910d5e97
7
+ data.tar.gz: 14d7b4b0e56183248e5a81378e677d8cfd8adff241a340ae83648911019143061b9cfc67bb410d26e0cffc537abc014474a97b27f44118ca848098643d2865f2
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency "fernet", "~> 2.1"
27
27
  spec.add_dependency "redis", "~> 3.1"
28
28
  spec.add_dependency "multi_json", "~> 1.9", ">= 1.9.3"
29
+ spec.add_dependency "mini_cache", "~> 1.1.0"
29
30
  end
@@ -1,13 +1,16 @@
1
1
  require "greencache/version"
2
2
  require "fernet"
3
3
  require "greencache/configuration"
4
+ require "mini_cache"
4
5
 
5
6
  Fernet::Configuration.run do |config|
6
7
  config.enforce_ttl = false
7
8
  end
8
9
 
9
10
  module Greencache
11
+
10
12
  class CacheMiss < RuntimeError; end
13
+
11
14
  class << self
12
15
  attr_writer :configuration
13
16
 
@@ -53,7 +56,9 @@ module Greencache
53
56
 
54
57
  private def get_value!(key, config)
55
58
  raise CacheMiss unless redis.exists(key)
56
- decrypt redis.get(key), config
59
+ result = memory_cache.get(key)
60
+ result = decrypt(redis.get(key), config) if result.nil?
61
+ result
57
62
  end
58
63
 
59
64
  def get_value(key, config)
@@ -63,6 +68,7 @@ module Greencache
63
68
 
64
69
  def set_value(key, value, config)
65
70
  redis.setex key, config[:cache_time], encrypt(value, config)
71
+ memory_cache.set(key, value, expires_in: 1)
66
72
  end
67
73
 
68
74
  def merge_config(config)
@@ -123,5 +129,9 @@ module Greencache
123
129
  def fernet
124
130
  ::Fernet
125
131
  end
132
+
133
+ def memory_cache
134
+ @@memory_cache ||= MiniCache::Store.new
135
+ end
126
136
  end
127
137
  end
@@ -1,3 +1,3 @@
1
1
  module Greencache
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -100,6 +100,19 @@ describe Greencache do
100
100
  rc.get_value("foo", {encrypt: true})
101
101
  end
102
102
 
103
+ it "gets a value from memory if a rapid re-lookup" do
104
+ expect(rc.redis).not_to receive(:get).with("foo")
105
+ rc.cache ("foo") { "bar" }
106
+ rc.cache ("foo") { "bar" }
107
+ end
108
+
109
+ it "gets a value from redis if a slow re-lookup" do
110
+ expect(rc.redis).to receive(:get).with("foo").once
111
+ rc.cache ("foo") { "bar" }
112
+ sleep(1)
113
+ rc.cache ("foo") { "bar" }
114
+ end
115
+
103
116
  it 'can set a value' do
104
117
  expect(rc.redis).to receive(:setex).with("foo", 100, '"bar"')
105
118
  rc.set_value("foo", "bar", {cache_time: 100, encrypt: false})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: greencache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil Middleton
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-12-12 00:00:00.000000000 Z
12
+ date: 2019-01-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -115,6 +115,20 @@ dependencies:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: 1.9.3
118
+ - !ruby/object:Gem::Dependency
119
+ name: mini_cache
120
+ requirement: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.1.0
125
+ type: :runtime
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.1.0
118
132
  description: A wrapper for Redis, for caching and encryption with Fernet
119
133
  email:
120
134
  - neil@neilmiddleton.com