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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae039da685356a9bdb0d13afbb9d632a7c625225
4
- data.tar.gz: aae94f15481b32301a2eeb4d76bf332e25b79db6
3
+ metadata.gz: 47ec5a52e5b81e40693ac35fd5e34c1dbd1975ee
4
+ data.tar.gz: 60dfeb981985a908b134f452ae2d29d38f9d6518
5
5
  SHA512:
6
- metadata.gz: b5a8bd7ed3b488e199310404b4fc077c256c11d07f9c86d7e53d11cb2b4fe2ea758490c7296631720f3a44c77648dc4d15379f89871bed94b964fbc5b538fefc
7
- data.tar.gz: c2a7e1c6cb15358b9237c3603524a477fda73e23b4e05d877ac44cdd8009c4b14ded2d651fd6ec3aa9b6c1f3d514099791e18fffa43fa410919c9583c8bb92bc
6
+ metadata.gz: 02b2c42311ead392b53abbefc0d3528a6da8bdb1cb53c167683a8bd537b9cc55c6bba9a24e0bde80b724c0c31e74db60376edb42605350958ef5c77bd162d416
7
+ data.tar.gz: 3ecb2fad3cdced22a5060d1cd9baa7d8cab21f005f3f0b3fd5d38ca8b8863a421bcbf6a633ff47eecd586d55808cac71e985cc523048d8b67a0e60a40ee2d837
@@ -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] = { 'created_at' => Time.now, 'entry' => value } unless value == '' || value == nil
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] && (Time.now - cache[key]['created_at']) < 1.hours
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.1
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-08-29 00:00:00.000000000 Z
12
+ date: 2014-09-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails-timeago