multi_store 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 62a66e00af3410958ab16d8bdbe4dc4ee9fc3d2d
4
+ data.tar.gz: b21250c9b334a72c89c4a61acf0e1065d69f78e0
5
+ SHA512:
6
+ metadata.gz: 947ef4f3340932f6e4a326709d74e092f71632aac618ce6e67ceabf1f39cacfe93c2ad427677a4358e2a7375fc0141a2064bf7b31ff5d0e8ad2a7d411038cbb5
7
+ data.tar.gz: ece24462b0f44995a1174572816af5d21e87732745bcbe18a3632a8834499ab0ac9fe4cb32da163304fcd15478b6cdfeabdb67fa8aef7faa2c8fb5785cadc197
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.hubconfig ADDED
@@ -0,0 +1 @@
1
+ {"default_branch": "master"}
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ multi_store
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
data/.solano.yml ADDED
@@ -0,0 +1,4 @@
1
+ tddium:
2
+ :ruby_version: '2.2.2'
3
+ :timeout_hook: 900
4
+ :timeout: 1200
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in multi_store.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ multi_store (0.1.0)
5
+ activesupport (>= 3, < 5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (4.2.5)
11
+ i18n (~> 0.7)
12
+ json (~> 1.7, >= 1.7.7)
13
+ minitest (~> 5.1)
14
+ thread_safe (~> 0.3, >= 0.3.4)
15
+ tzinfo (~> 1.1)
16
+ diff-lcs (1.2.5)
17
+ i18n (0.7.0)
18
+ json (1.8.3)
19
+ minitest (5.8.3)
20
+ rake (10.4.2)
21
+ rspec (3.4.0)
22
+ rspec-core (~> 3.4.0)
23
+ rspec-expectations (~> 3.4.0)
24
+ rspec-mocks (~> 3.4.0)
25
+ rspec-core (3.4.1)
26
+ rspec-support (~> 3.4.0)
27
+ rspec-expectations (3.4.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.4.0)
30
+ rspec-mocks (3.4.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.4.0)
33
+ rspec-support (3.4.1)
34
+ thread_safe (0.3.5)
35
+ tzinfo (1.2.2)
36
+ thread_safe (~> 0.1)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ bundler (~> 1.10)
43
+ multi_store!
44
+ rake (~> 10.0)
45
+ rspec
46
+
47
+ BUNDLED WITH
48
+ 1.10.6
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # MultiStore
2
+
3
+ MultiStore allows you to delegate to multiple ActiveSupport cache stores.
4
+ This makes it easy to implement behaviors such as "cache frequently used things locally, but infrequently used things remotely".
5
+
6
+ ## Usage
7
+ Add an initializer that sets the rails cache, and tier your caches to your heart's content!
8
+
9
+ ```ruby
10
+ stores = [
11
+ ActiveSupport::Cache::MemoryStore.new,
12
+ ActiveSupport::Cache::FileStore.new('/tmp/cache')
13
+ ]
14
+ ActionController::Base.cache_store = :multi_store, stores
15
+ Rails.cache = ActionController::Base.cache_store
16
+ ```
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'multi_store'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install multi_store
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Gusto/multi_store.
37
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,50 @@
1
+ module ActiveSupport
2
+ module Cache
3
+ class MultiStore < Store
4
+ def initialize(*stores)
5
+ @monitor = Monitor.new
6
+ @stores = stores
7
+ super(stores.extract_options!)
8
+ end
9
+
10
+ def self.send_to_all(*methods)
11
+ methods.each do |method|
12
+ define_method method do |*args|
13
+ synchronize do
14
+ @stores.map { |store| store.send(method, *args) }
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ send_to_all :delete_matched, :increment, :decrement, :cleanup, :clear
21
+
22
+ protected
23
+ # Read an entry from the cache implementation. Subclasses must implement
24
+ # this method.
25
+ def read_entry(key, options) # :nodoc:
26
+ @stores.each_with_index do |store, index|
27
+ entry = store.send(:read_entry, key, options)
28
+ if entry && !entry.expired?
29
+ promote_entry(key, entry, index)
30
+ return entry
31
+ end
32
+ end
33
+ nil
34
+ end
35
+
36
+ send_to_all :write_entry, :delete_entry
37
+
38
+ private
39
+ def synchronize(&block) # :nodoc:
40
+ @monitor.synchronize(&block)
41
+ end
42
+
43
+ def promote_entry(key, entry, index)
44
+ @stores.first(index).each do |store|
45
+ store.write(key, entry.value)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ require 'multi_store/version'
2
+ require 'active_support'
3
+ require 'active_support/cache/multi_store'
@@ -0,0 +1,3 @@
1
+ module MultiStore
2
+ VERSION = '0.1.0'
3
+ 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 'multi_store/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'multi_store'
8
+ spec.version = MultiStore::VERSION
9
+ spec.authors = ['Matt Wilde']
10
+ spec.email = ['matt@gusto.com']
11
+
12
+ spec.summary = %q{An ActiveSupport::Store that delegates to a series of stores in order.}
13
+ spec.homepage = 'https://github.com/Gusto/multi_store'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'activesupport', '>= 3', '< 5'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.10'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec'
26
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: multi_store
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Wilde
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-09 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'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.10'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.10'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ description:
76
+ email:
77
+ - matt@gusto.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - ".hubconfig"
84
+ - ".rspec"
85
+ - ".ruby-gemset"
86
+ - ".ruby-version"
87
+ - ".solano.yml"
88
+ - Gemfile
89
+ - Gemfile.lock
90
+ - README.md
91
+ - Rakefile
92
+ - lib/active_support/cache/multi_store.rb
93
+ - lib/multi_store.rb
94
+ - lib/multi_store/version.rb
95
+ - multi_store.gemspec
96
+ homepage: https://github.com/Gusto/multi_store
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.4.8
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: An ActiveSupport::Store that delegates to a series of stores in order.
120
+ test_files: []