namespaced-cache 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +21 -0
- data/Rakefile +10 -0
- data/lib/active_support/cache/namespaced_store.rb +46 -0
- data/lib/namespaced-cache.rb +2 -0
- data/lib/namespaced_cache/version.rb +3 -0
- data/namespaced-cache.gemspec +26 -0
- data/spec/active_support/cache/prefixed_store_spec.rb +80 -0
- data/spec/spec_helper.rb +12 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: df2ceaeb59b553fdfb25f4bdfcece83abacbcaf0
|
4
|
+
data.tar.gz: 784a96a45979f32d4484483000ebc34662b2642f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2a4816cda3f35055c6b22d7d7ff2cf6e36220f49901f1632d9df1b2410fe8c10eb80cb963745df963503e49b6a2016007b634826c095f4ca625324e0b7aeb22c
|
7
|
+
data.tar.gz: 6259320fe062835b32f9f326991d6d3f7db4eebc8cb5ecde89b9583ab908441e6eab11a6a1e282cc1ca981d735c29dc0588368670b4df0adbe0d1e2cfe3abe3b
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Eric J. Holmes
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# ActiveSupport::Cache::NamespacedStore
|
2
|
+
|
3
|
+
A simple ActiveSupport::Cache implementation that wraps another implementation to prefix/namespace keys.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
Rails.cache.write('prefix:1', 'foo')
|
9
|
+
|
10
|
+
cache = ActiveSupport::Cache::NamespacedStore.new 'prefix:', Rails.cache
|
11
|
+
cache.read '1'
|
12
|
+
# => 'foo'
|
13
|
+
```
|
14
|
+
|
15
|
+
## Contributing
|
16
|
+
|
17
|
+
1. Fork it
|
18
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
19
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
20
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
21
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'active_support/cache'
|
2
|
+
|
3
|
+
module ActiveSupport::Cache
|
4
|
+
# Public: A wrapper around an ActiveSupport::Cache to prefix all keys.
|
5
|
+
#
|
6
|
+
# Example
|
7
|
+
#
|
8
|
+
# cache = ActiveSupport::Cache::NamespacedStore.new 'namespace:', Rails.cache
|
9
|
+
class NamespacedStore
|
10
|
+
attr_reader :namespace, :store
|
11
|
+
|
12
|
+
def initialize(namespace, store)
|
13
|
+
@namespace = namespace
|
14
|
+
@store = store
|
15
|
+
end
|
16
|
+
|
17
|
+
def read(key, *args, &block)
|
18
|
+
store.read(namespaced(key), *args, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def read_multi(*keys)
|
22
|
+
k = keys.map { |key| namespaced(key) }
|
23
|
+
store.read_multi(*k).each_with_object(Hash.new) do |t,memo|
|
24
|
+
memo[t[0].sub(namespace, '')] = t[1]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def write(key, *args, &block)
|
29
|
+
store.write(namespaced(key), *args, &block)
|
30
|
+
end
|
31
|
+
|
32
|
+
def fetch(key, *args, &block)
|
33
|
+
store.fetch(namespaced(key), *args, &block)
|
34
|
+
end
|
35
|
+
|
36
|
+
def clear
|
37
|
+
store.delete_matched(namespace)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def namespaced(key)
|
43
|
+
"#{namespace}#{key}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'namespaced_cache/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'namespaced-cache'
|
8
|
+
spec.version = NamespacedCache::VERSION
|
9
|
+
spec.authors = ['Eric J. Holmes']
|
10
|
+
spec.email = ['eric@ejholmes.net']
|
11
|
+
spec.description = %q{An ActiveSupport::Cache implementation for prefixing.}
|
12
|
+
spec.summary = %q{An ActiveSupport::Cache implementation for prefixing.}
|
13
|
+
spec.homepage = 'https://github.com/remind101/namespaced-cache'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'activesupport', '>= 3.0'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.4.2'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.1.0'
|
26
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveSupport::Cache::NamespacedStore do
|
4
|
+
let(:store) { ActiveSupport::Cache::MemoryStore.new }
|
5
|
+
let(:cache) { described_class.new 'prefix:', store }
|
6
|
+
|
7
|
+
before do
|
8
|
+
store.clear
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#write' do
|
12
|
+
it 'writes to the cache' do
|
13
|
+
expect {
|
14
|
+
cache.write('key', 'value')
|
15
|
+
}.to change { store.read('prefix:key') }.from(nil).to('value')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#read' do
|
20
|
+
context 'when the item is in cache' do
|
21
|
+
before do
|
22
|
+
store.write('prefix:key', 'value')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'reads the item' do
|
26
|
+
expect(cache.read('key')).to eq 'value'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#read_multi' do
|
32
|
+
context 'when no items are in cache' do
|
33
|
+
it 'does not blow up' do
|
34
|
+
expect(cache.read_multi('key1')).to eq Hash.new
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when the items are in cache' do
|
39
|
+
before do
|
40
|
+
store.write('prefix:key1', 'value1')
|
41
|
+
store.write('prefix:key2', 'value2')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'reads the items' do
|
45
|
+
expect(cache.read_multi('key1', 'key2')).to eq 'key1' => 'value1', 'key2' => 'value2'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#fetch' do
|
51
|
+
context 'when the item is not in cache' do
|
52
|
+
it 'caches the item' do
|
53
|
+
expect {
|
54
|
+
cache.fetch('key') do
|
55
|
+
'value'
|
56
|
+
end
|
57
|
+
}.to change { store.read('prefix:key') }.from(nil).to('value')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#clear' do
|
63
|
+
before do
|
64
|
+
store.write('prefix:key1', 'value1')
|
65
|
+
store.write('key1', 'value1')
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'clears prefixed keys' do
|
69
|
+
expect {
|
70
|
+
cache.clear
|
71
|
+
}.to change { store.read('prefix:key1') }.from('value1').to(nil)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'does not clear keys that are not prefixed' do
|
75
|
+
expect {
|
76
|
+
cache.clear
|
77
|
+
}.to_not change { store.read('key1') }.from('value1')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.require :default, :test
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.order = 'random'
|
6
|
+
config.filter_run :focus => true
|
7
|
+
config.run_all_when_everything_filtered = true
|
8
|
+
end
|
9
|
+
|
10
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
11
|
+
# in spec/support/ and its subdirectories.
|
12
|
+
Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f}
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: namespaced-cache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric J. Holmes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 10.4.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 10.4.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.1.0
|
69
|
+
description: An ActiveSupport::Cache implementation for prefixing.
|
70
|
+
email:
|
71
|
+
- eric@ejholmes.net
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/active_support/cache/namespaced_store.rb
|
83
|
+
- lib/namespaced-cache.rb
|
84
|
+
- lib/namespaced_cache/version.rb
|
85
|
+
- namespaced-cache.gemspec
|
86
|
+
- spec/active_support/cache/prefixed_store_spec.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
homepage: https://github.com/remind101/namespaced-cache
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.0.14
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: An ActiveSupport::Cache implementation for prefixing.
|
112
|
+
test_files:
|
113
|
+
- spec/active_support/cache/prefixed_store_spec.rb
|
114
|
+
- spec/spec_helper.rb
|