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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 921749f49838a742e100da56d3db616b8d3688fd
4
- data.tar.gz: d1c158cd682accd7d97c0efef882e86f97d6677f
3
+ metadata.gz: 75ce3177b627611fb2c9bf28bacd5c7295bbe185
4
+ data.tar.gz: 6b2a16815c93bd3ecde18e63b58e5ced7104f6e9
5
5
  SHA512:
6
- metadata.gz: 30ea1dd82faae352b59baa623ba331dc88c9cb53161c6761fee08db5e1e3e03a1796901720d622113dbee64dd08b8781ac1ae5ec1f43d2502bb4fb199cf215a4
7
- data.tar.gz: 45f86b016de49a758f391732cd8bdac77ceca80dcfb596267dcbf8a7b7b139590a8012bec04d01fe67c1a8481dd11153fcb3cc1f752f5618a5d6bfa701ab4295
6
+ metadata.gz: 5153923a7290b7ea8c1f11def5d84fb5baa990ecb692022e4d327bd1f7c42511cd54fcf56971fc99070af33e3773295f8b3c24b311feab28ec490f5ab6f086bb
7
+ data.tar.gz: 42865aede50bb7d86905b5db6cecb7cf126309b197edc5bfd887a7b06f443dfbea9cb2c95ae76a506916c4bef94680d11c684f46a8e5c8949a4c3fdb0bce0e53
@@ -1,7 +1,9 @@
1
+ gemfile:
2
+ - gemfiles/Gemfile.rails3
3
+ - gemfiles/Gemfile.rails4
1
4
  rvm:
2
- - 1.9.2
3
- - 1.9.3
4
5
  - 2.0.0
5
6
  - 2.1.1
6
7
  - 2.1.2
7
- cache: bundler
8
+ cache: bundler
9
+ sudo: false
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'
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Julik Tarkhanov
1
+ Copyright (c) 2014 Julik Tarkhanov for WeTransfer
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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
- == Copyright
42
+ ## Copyright
41
43
 
42
- Copyright (c) 2014 Julik Tarkhanov. See LICENSE.txt for
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/julik/prefixed_cache_store"
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
@@ -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.1'
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(prefix_key(name), amount, options)
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(prefix_key(name), amount, options)
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.1 ruby lib
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.1"
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 = "2014-10-30"
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/julik/prefixed_cache_store"
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 'fetch_multi' do
99
- it 'performs a multi-fetch calling the backing store' do
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
- results = subject.fetch_multi('record1', 'record2') do | key_to_fetch |
106
- "This is #{key_to_fetch}"
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
- expect(results).to eq(["This is record1", "This is record2"])
141
+ subject = described_class.new(some_store, 'pre')
110
142
 
111
- results_from_cache = subject.fetch_multi('record1', 'record2') do | key_to_fetch |
112
- raise "Should not be called"
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
- expect(results_from_cache).to eq(["This is record1", "This is record2"])
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
- expect(some_store.read("pre-version")).to eq(0)
117
- expect(some_store.read("pre-0-record1")).to eq('This is record1')
118
- expect(some_store.read("pre-0-record2")).to eq('This is record2')
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
 
@@ -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.1
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: 2014-10-30 00:00:00.000000000 Z
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/julik/prefixed_cache_store
103
+ homepage: http://github.com/WeTransfer/prefixed_cache_store
102
104
  licenses:
103
105
  - MIT
104
106
  metadata: {}