atomic_redis_cache 0.2.1 → 0.2.2

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.
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - ruby-head
5
+ - jruby-head
6
+ - 2.1.0
7
+ - 1.9.3
8
+ - jruby-18mode
9
+ - jruby-19mode
10
+ - ree
11
+
12
+ script: 'bundle exec rake'
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # AtomicRedisCache
2
2
 
3
+ [![Build Status](https://travis-ci.org/anujdas/atomic_redis_cache.png?branch=master)](https://travis-ci.org/anujdas/atomic_redis_cache)
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/atomic_redis_cache.png)](http://badge.fury.io/rb/atomic_redis_cache)
6
+
3
7
  AtomicRedisCache is an overlay on top of Redis that allows you to use it much
4
8
  like the Rails cache (ActiveSupport::Cache). Usage centers around the `.fetch()`
5
9
  method, which reads from a key if present and valid, or else evaluates the
@@ -32,20 +36,43 @@ Or install it yourself as:
32
36
  Ensure that you set the value of `AtomicRedisCache.redis`. This can be either an
33
37
  instance of redis-rb (or compatible), or a lambda/Proc evaluating to one. Ex.
34
38
 
35
- ``` AtomicRedisCache.redis = Redis.new(:host => '127.0.0.1', :port => 6379) ```
39
+ ```
40
+ AtomicRedisCache.redis = Redis.new(:host => '127.0.0.1', :port => 6379)
41
+ ```
36
42
 
37
43
  Then use it as you would Rails.cache:
38
44
 
39
45
  ```
40
- >> v = AtomicRedisCache.fetch('key') { Faraday.get('example.com').status }
46
+ >> AtomicRedisCache.fetch('key') { Faraday.get('http://example.com').status }
41
47
  => 200 # network call made
42
- >> v = AtomicRedisCache.fetch('key') { raise 'Network call attempted' }
43
- => 200 # value read from cache ```
48
+ >> AtomicRedisCache.fetch('key') { raise }
49
+ => 200 # value read from cache; block not called
50
+ >> AtomicRedisCache.write('key', {:new => 'value'})
51
+ => true
52
+ >> AtomicRedisCache.read('key')
53
+ => {:new => "value"}
54
+ >> AtomicRedisCache.delete('key')
55
+ => true
56
+ >> AtomicRedisCache.read('key')
57
+ => nil
58
+ ```
44
59
 
45
- There are a couple of configurable options can be set per fetch:
60
+ There are a couple of configurable options that can be set per fetch/write:
46
61
  - `:expires_in` - expiry in seconds; defaults to a day
47
- - `:race_condition_ttl` - time to lock down key for recalculation
48
- - `:max_retries` - # of times to retry cache refresh before expiring
62
+ - `:race_condition_ttl` - time to lock down key for recalculation; default 30s
63
+ - `:max_retries` - # of times to retry cache refresh before expiring; default 3
64
+
65
+ AtomicRedisCache is most useful when wrapped around expensive but rarely
66
+ changing calls, such as network APIs, that are hit frequently by many
67
+ processes. For instance,
68
+
69
+ ```
70
+ AtomicRedisCache.fetch('search.results') do
71
+ JSON.parse(Faraday.get('https://internal-api/search?q=value').body)
72
+ end
73
+ ```
74
+
75
+ will prevent your `internal-api` from getting pounded when the cached expires.
49
76
 
50
77
  ## Contributing
51
78
 
@@ -23,5 +23,9 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'rake'
24
24
  spec.add_development_dependency 'rspec', '~> 3.0'
25
25
  spec.add_development_dependency 'fakeredis'
26
- spec.add_development_dependency 'timecop'
26
+ if RUBY_VERSION == '1.8.7'
27
+ spec.add_development_dependency 'timecop', '0.5.2'
28
+ else
29
+ spec.add_development_dependency 'timecop'
30
+ end
27
31
  end
@@ -1,3 +1,3 @@
1
1
  module AtomicRedisCache
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atomic_redis_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -99,6 +99,7 @@ extensions: []
99
99
  extra_rdoc_files: []
100
100
  files:
101
101
  - ".gitignore"
102
+ - ".travis.yml"
102
103
  - Gemfile
103
104
  - LICENSE.txt
104
105
  - README.md