prefixed_cache_store 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -3
- data/Gemfile +0 -5
- data/LICENSE.txt +1 -1
- data/README.md +4 -2
- data/Rakefile +1 -1
- data/gemfiles/Gemfile.rails3 +10 -0
- data/gemfiles/Gemfile.rails4 +12 -0
- data/lib/prefixed_cache_store.rb +15 -3
- data/prefixed_cache_store.gemspec +6 -4
- data/spec/prefixed_cache_store_spec.rb +76 -12
- data/spec/spec_helper.rb +0 -16
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75ce3177b627611fb2c9bf28bacd5c7295bbe185
|
4
|
+
data.tar.gz: 6b2a16815c93bd3ecde18e63b58e5ced7104f6e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5153923a7290b7ea8c1f11def5d84fb5baa990ecb692022e4d327bd1f7c42511cd54fcf56971fc99070af33e3773295f8b3c24b311feab28ec490f5ab6f086bb
|
7
|
+
data.tar.gz: 42865aede50bb7d86905b5db6cecb7cf126309b197edc5bfd887a7b06f443dfbea9cb2c95ae76a506916c4bef94680d11c684f46a8e5c8949a4c3fdb0bce0e53
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
5
2
|
|
6
|
-
# Add dependencies to develop your gem here.
|
7
|
-
# Include everything needed to run rake, tests, features, etc.
|
8
3
|
group :development do
|
9
4
|
gem "activesupport", "~> 4"
|
10
5
|
gem 'rspec', '~> 3.1'
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
## prefixed_cache_store
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/WeTransfer/prefixed_cache_store.svg?branch=master)](https://travis-ci.org/WeTransfer/prefixed_cache_store)
|
4
|
+
|
3
5
|
A cache wrapper for ActiveSupport that allows you to expire parts of your cache imperatively.
|
4
6
|
|
5
7
|
Sometimes you need to selectively nuke parts of your cache. All cache stores for Rails support the `Store#clear()`
|
@@ -37,8 +39,8 @@ The gem has been extensively tested in production with Rails 3.x but should work
|
|
37
39
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
38
40
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
39
41
|
|
40
|
-
|
42
|
+
## Copyright
|
41
43
|
|
42
|
-
Copyright (c) 2014
|
44
|
+
Copyright (c) 2014 WeTransfer. See LICENSE.txt for
|
43
45
|
further details.
|
44
46
|
|
data/Rakefile
CHANGED
@@ -17,7 +17,7 @@ Jeweler::Tasks.new do |gem|
|
|
17
17
|
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
18
18
|
gem.version = PrefixedCacheStore::VERSION
|
19
19
|
gem.name = "prefixed_cache_store"
|
20
|
-
gem.homepage = "http://github.com/
|
20
|
+
gem.homepage = "http://github.com/WeTransfer/prefixed_cache_store"
|
21
21
|
gem.license = "MIT"
|
22
22
|
gem.summary = %Q{Namespaced versioned cache wrapper for ActiveSupport}
|
23
23
|
gem.description = %Q{Allows you to expire parts of your cache separately}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
gem 'activesupport', "~> 4"
|
3
|
+
|
4
|
+
# Add dependencies to develop your gem here.
|
5
|
+
# Include everything needed to run rake, tests, features, etc.
|
6
|
+
group :development do
|
7
|
+
gem 'rspec', '~> 3.1'
|
8
|
+
gem "bundler", "~> 1.0"
|
9
|
+
gem "jeweler", "~> 2.0.1"
|
10
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
gem 'activesupport', "~> 3", '< 4'
|
3
|
+
|
4
|
+
# Add dependencies to develop your gem here.
|
5
|
+
# Include everything needed to run rake, tests, features, etc.
|
6
|
+
group :development do
|
7
|
+
gem 'sqlite3'
|
8
|
+
gem "rspec", "~> 2.4"
|
9
|
+
gem "rdoc", "~> 3.12"
|
10
|
+
gem "bundler", "~> 1.0"
|
11
|
+
gem "jeweler", "1.8.4" # The last without Nokogiri
|
12
|
+
end
|
data/lib/prefixed_cache_store.rb
CHANGED
@@ -5,7 +5,7 @@ require 'forwardable'
|
|
5
5
|
# for the namespace and the version number that can be ratched up to "unlink" all the related keys.
|
6
6
|
# It assumes that the keys are being evicted automatically if they do not get used often.
|
7
7
|
class PrefixedCacheStore
|
8
|
-
VERSION = '0.2.
|
8
|
+
VERSION = '0.2.2'
|
9
9
|
|
10
10
|
RETAIN_PREFIX_FOR_SECONDS = 10
|
11
11
|
|
@@ -33,6 +33,10 @@ class PrefixedCacheStore
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def fetch_multi(*names)
|
36
|
+
if !@store.respond_to?(:fetch_multi)
|
37
|
+
raise NoMethodError, "#{@store.inspect} does not support fetch_multi()"
|
38
|
+
end
|
39
|
+
|
36
40
|
options = names.extract_options!
|
37
41
|
prefixed_keys = names.map{|e| prefix_key(e) }
|
38
42
|
@store.fetch_multi(*prefixed_keys, options) do | prefixed_key |
|
@@ -70,12 +74,20 @@ class PrefixedCacheStore
|
|
70
74
|
|
71
75
|
# Increment a cached value.
|
72
76
|
def increment(name, amount = 1, options=nil)
|
73
|
-
@store.increment
|
77
|
+
if @store.method(:increment).parameters.length > 2
|
78
|
+
@store.increment(prefix_key(name), amount, options)
|
79
|
+
else
|
80
|
+
@store.increment(prefix_key(name), amount) # Toss the options
|
81
|
+
end
|
74
82
|
end
|
75
83
|
|
76
84
|
# Decrement a cached value.
|
77
85
|
def decrement(name, amount = 1, options=nil)
|
78
|
-
@store.decrement
|
86
|
+
if @store.method(:decrement).parameters.length > 2
|
87
|
+
@store.decrement(prefix_key(name), amount, options)
|
88
|
+
else
|
89
|
+
@store.increment(prefix_key(name), amount) # Toss the options
|
90
|
+
end
|
79
91
|
end
|
80
92
|
|
81
93
|
# Bump the version prefix making all keys obsolete.
|
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: prefixed_cache_store 0.2.
|
5
|
+
# stub: prefixed_cache_store 0.2.2 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "prefixed_cache_store"
|
9
|
-
s.version = "0.2.
|
9
|
+
s.version = "0.2.2"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Julik Tarkhanov"]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2016-02-10"
|
15
15
|
s.description = "Allows you to expire parts of your cache separately"
|
16
16
|
s.email = "me@julik.nl"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -25,12 +25,14 @@ Gem::Specification.new do |s|
|
|
25
25
|
"LICENSE.txt",
|
26
26
|
"README.md",
|
27
27
|
"Rakefile",
|
28
|
+
"gemfiles/Gemfile.rails3",
|
29
|
+
"gemfiles/Gemfile.rails4",
|
28
30
|
"lib/prefixed_cache_store.rb",
|
29
31
|
"prefixed_cache_store.gemspec",
|
30
32
|
"spec/prefixed_cache_store_spec.rb",
|
31
33
|
"spec/spec_helper.rb"
|
32
34
|
]
|
33
|
-
s.homepage = "http://github.com/
|
35
|
+
s.homepage = "http://github.com/WeTransfer/prefixed_cache_store"
|
34
36
|
s.licenses = ["MIT"]
|
35
37
|
s.rubygems_version = "2.2.2"
|
36
38
|
s.summary = "Namespaced versioned cache wrapper for ActiveSupport"
|
@@ -95,27 +95,91 @@ describe PrefixedCacheStore do
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
-
describe '
|
99
|
-
it '
|
98
|
+
describe 'increment' do
|
99
|
+
it 'increments the counter' do
|
100
|
+
some_store = ActiveSupport::Cache::MemoryStore.new
|
101
|
+
subject = described_class.new(some_store, 'pre')
|
102
|
+
|
103
|
+
subject.increment("ctr")
|
104
|
+
subject.increment("ctr", 15)
|
105
|
+
subject.increment("ctr", 2, Hash.new)
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'increments the counter even if the underlying Store does not support the options argument (like redis-activesupport)' do
|
109
|
+
# redis-activesupport does not support options{} for the last argument
|
100
110
|
some_store = ActiveSupport::Cache::MemoryStore.new
|
111
|
+
class << some_store
|
112
|
+
def increment(counter_name, incr=1)
|
113
|
+
end
|
114
|
+
end
|
101
115
|
|
102
116
|
subject = described_class.new(some_store, 'pre')
|
103
|
-
expect(subject.current_version_number).to eq(0)
|
104
117
|
|
105
|
-
|
106
|
-
|
118
|
+
subject.increment("ctr")
|
119
|
+
subject.increment("ctr", 15)
|
120
|
+
subject.increment("ctr", 2, Hash.new)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe 'decrement' do
|
125
|
+
it 'decrement the counter' do
|
126
|
+
some_store = ActiveSupport::Cache::MemoryStore.new
|
127
|
+
subject = described_class.new(some_store, 'pre')
|
128
|
+
|
129
|
+
subject.decrement("ctr")
|
130
|
+
subject.decrement("ctr", 15)
|
131
|
+
subject.decrement("ctr", 2, Hash.new)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'decrement the counter even if the underlying Store does not support the options argument (like redis-activesupport)' do
|
135
|
+
some_store = ActiveSupport::Cache::MemoryStore.new
|
136
|
+
class << some_store
|
137
|
+
def decrement(counter_name, incr=1)
|
138
|
+
end
|
107
139
|
end
|
108
140
|
|
109
|
-
|
141
|
+
subject = described_class.new(some_store, 'pre')
|
110
142
|
|
111
|
-
|
112
|
-
|
143
|
+
subject.decrement("ctr")
|
144
|
+
subject.decrement("ctr", 15)
|
145
|
+
subject.decrement("ctr", 2, Hash.new)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe 'fetch_multi' do
|
150
|
+
if ActiveSupport::VERSION::MAJOR < 4
|
151
|
+
it 'raises a NoMethodError' do
|
152
|
+
some_store = ActiveSupport::Cache::MemoryStore.new
|
153
|
+
subject = described_class.new(some_store, 'pre')
|
154
|
+
|
155
|
+
expect {
|
156
|
+
subject.fetch_multi('key1, key2')
|
157
|
+
}.to raise_error(NoMethodError, /does not support/)
|
113
158
|
end
|
114
|
-
|
159
|
+
end
|
160
|
+
|
161
|
+
if ActiveSupport::VERSION::MAJOR > 3
|
162
|
+
it 'Rails 4 - performs a multi-fetch calling the backing store' do
|
163
|
+
some_store = ActiveSupport::Cache::MemoryStore.new
|
115
164
|
|
116
|
-
|
117
|
-
|
118
|
-
|
165
|
+
subject = described_class.new(some_store, 'pre')
|
166
|
+
expect(subject.current_version_number).to eq(0)
|
167
|
+
|
168
|
+
results = subject.fetch_multi('record1', 'record2') do | key_to_fetch |
|
169
|
+
"This is #{key_to_fetch}"
|
170
|
+
end
|
171
|
+
|
172
|
+
expect(results).to eq({"pre-0-record1"=>"This is record1", "pre-0-record2"=>"This is record2"})
|
173
|
+
|
174
|
+
results_from_cache = subject.fetch_multi('record1', 'record2') do | key_to_fetch |
|
175
|
+
raise "Should not be called"
|
176
|
+
end
|
177
|
+
expect(results_from_cache).to eq({"pre-0-record1"=>"This is record1", "pre-0-record2"=>"This is record2"})
|
178
|
+
|
179
|
+
expect(some_store.read("pre-version")).to eq(0)
|
180
|
+
expect(some_store.read("pre-0-record1")).to eq('This is record1')
|
181
|
+
expect(some_store.read("pre-0-record2")).to eq('This is record2')
|
182
|
+
end
|
119
183
|
end
|
120
184
|
end
|
121
185
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,19 +1,3 @@
|
|
1
|
-
require 'simplecov'
|
2
|
-
|
3
|
-
module SimpleCov::Configuration
|
4
|
-
def clean_filters
|
5
|
-
@filters = []
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
SimpleCov.configure do
|
10
|
-
clean_filters
|
11
|
-
load_profile 'test_frameworks'
|
12
|
-
end
|
13
|
-
|
14
|
-
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
-
add_filter "/.rvm/"
|
16
|
-
end
|
17
1
|
require 'rubygems'
|
18
2
|
require 'bundler'
|
19
3
|
begin
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prefixed_cache_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julik Tarkhanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -94,11 +94,13 @@ files:
|
|
94
94
|
- LICENSE.txt
|
95
95
|
- README.md
|
96
96
|
- Rakefile
|
97
|
+
- gemfiles/Gemfile.rails3
|
98
|
+
- gemfiles/Gemfile.rails4
|
97
99
|
- lib/prefixed_cache_store.rb
|
98
100
|
- prefixed_cache_store.gemspec
|
99
101
|
- spec/prefixed_cache_store_spec.rb
|
100
102
|
- spec/spec_helper.rb
|
101
|
-
homepage: http://github.com/
|
103
|
+
homepage: http://github.com/WeTransfer/prefixed_cache_store
|
102
104
|
licenses:
|
103
105
|
- MIT
|
104
106
|
metadata: {}
|