fragment_client 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fragment_client.rb +1 -1
- data/lib/memory_cache.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47ec5a52e5b81e40693ac35fd5e34c1dbd1975ee
|
4
|
+
data.tar.gz: 60dfeb981985a908b134f452ae2d29d38f9d6518
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02b2c42311ead392b53abbefc0d3528a6da8bdb1cb53c167683a8bd537b9cc55c6bba9a24e0bde80b724c0c31e74db60376edb42605350958ef5c77bd162d416
|
7
|
+
data.tar.gz: 3ecb2fad3cdced22a5060d1cd9baa7d8cab21f005f3f0b3fd5d38ca8b8863a421bcbf6a633ff47eecd586d55808cac71e985cc523048d8b67a0e60a40ee2d837
|
data/lib/fragment_client.rb
CHANGED
@@ -12,7 +12,7 @@ class FragmentClient
|
|
12
12
|
|
13
13
|
def fetch(section, options={})
|
14
14
|
set_params(options)
|
15
|
-
cache.fetch(section + option_params) { request[section] }
|
15
|
+
cache.fetch(section + option_params, expires_in: ENV["FRAGMENT_CLIENT_CACHE_TIME"] || 1.hour) { request[section] }
|
16
16
|
end
|
17
17
|
|
18
18
|
private
|
data/lib/memory_cache.rb
CHANGED
@@ -5,19 +5,19 @@ class MemoryCache
|
|
5
5
|
self.cache = {}
|
6
6
|
end
|
7
7
|
|
8
|
-
def fetch(key, &block)
|
9
|
-
validate?(key) ? read(key) : write(key, block.call)['entry']
|
8
|
+
def fetch(key, hash={ expires_in: 1.hour }, &block)
|
9
|
+
validate?(key) ? read(key) : write(key, block.call, hash)['entry']
|
10
10
|
end
|
11
11
|
|
12
12
|
def read(key)
|
13
13
|
cache[key]['entry']
|
14
14
|
end
|
15
15
|
|
16
|
-
def write(key, value)
|
17
|
-
self.cache[key] = { '
|
16
|
+
def write(key, value, hash={ expires_in: 1.hour })
|
17
|
+
self.cache[key] = { 'valid_until' => (Time.now + hash[:expires_in]), 'entry' => value } unless value == '' || value == nil
|
18
18
|
end
|
19
19
|
|
20
20
|
def validate?(key)
|
21
|
-
cache[key] &&
|
21
|
+
cache[key] && Time.now < cache[key]['valid_until']
|
22
22
|
end
|
23
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fragment_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Atkinson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails-timeago
|