greencache 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/greencache.gemspec +1 -0
- data/lib/greencache.rb +11 -1
- data/lib/greencache/version.rb +1 -1
- data/spec/greencache_spec.rb +13 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89089770b5bbd5abf1e5d6a52d170b86735de343c39255d5693a662e58b8e12b
|
4
|
+
data.tar.gz: 8190ba01e4aad4196ecfdcfe561523fe983b45bc6d6b7069dc5c61f1030c72c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da86d39a8c8c3c1c546d8e58919fa5cd29e2ca1ef9871f9652c46f4f007842782792de66caafa364298bf92be0ddd69536979e141f289469f06c4625910d5e97
|
7
|
+
data.tar.gz: 14d7b4b0e56183248e5a81378e677d8cfd8adff241a340ae83648911019143061b9cfc67bb410d26e0cffc537abc014474a97b27f44118ca848098643d2865f2
|
data/greencache.gemspec
CHANGED
data/lib/greencache.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/greencache/version.rb
CHANGED
data/spec/greencache_spec.rb
CHANGED
@@ -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.
|
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:
|
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
|