multi_cache-rails 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b11ca23b8b0966e07e4fcd502c4f5e191ad39e9b
4
+ data.tar.gz: dc86d49816fbef720f1860477b0f6a1d9d82a55e
5
+ SHA512:
6
+ metadata.gz: 5e1dbfd5b52f46de9d503d50a3ce5c6b3506fbc6aa7192ea9ae151b25346633f13e322309d925b16aa735b14fa498a7fb594e6a3fc17ce96a978b9237e800b51
7
+ data.tar.gz: fb99c19642a39986d534dbe33e80c12f5955bd845c963ffa214b9f712576409aaf797a17f3c053f90a7be29ceccf4b6c76f7c90d415d420a34a42a83c8f8e5a9
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in multicache-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Takashi Uesugi
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,47 @@
1
+ # MultiCache::Rails
2
+
3
+ Multiple cache configuration for Ruby On Rails.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'multi_cache-rails'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install multi_cache-rails
19
+
20
+ ## Usage
21
+
22
+ On `Application.configure` , it's like `project_root/config/emvironments/production.rb`
23
+
24
+ ```
25
+ YourProject::Application.configure do
26
+
27
+ config.cache_store = :dalli_store, 'localhost', { :namespace => 'Fril', :compress => true }
28
+ config.cache_store = {
29
+ name: :secondary,
30
+ setting: :memory_store
31
+ }
32
+ end
33
+ ```
34
+
35
+ Then, In your project, you can use the caches like below,
36
+ ```
37
+ Rails.cache.read("something") # fetch cached object from :dalli_store
38
+ Rails.cache(:secondary).read("something") # fetch cached object from :memory_store
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( https://github.com/[my-github-username]/multicache-rails/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
7
+
8
+ task :console do
9
+ exec 'irb -r multi_cache -I ./lib'
10
+ end
@@ -0,0 +1,35 @@
1
+ module Rails
2
+ class Application
3
+ class Configuration
4
+
5
+ def cache_store=(cache_setting)
6
+ init_cache_store
7
+
8
+ case cache_setting
9
+ when Hash
10
+ key = cache_setting[:name]
11
+ @cache_store[key] = cache_setting[:setting]
12
+ else
13
+ @cache_store[:default] = cache_setting
14
+ end
15
+ @cache_store
16
+ end
17
+
18
+ def cache_store(cache_name = :default)
19
+ init_cache_store
20
+ @cache_store[cache_name] || @cache_store[:default]
21
+ end
22
+
23
+ def cache_store_names
24
+ return [] if @cache_store.blank?
25
+ @cache_store.keys
26
+ end
27
+
28
+ private
29
+
30
+ def init_cache_store
31
+ @cache_store = { default: @cache_store } if @cache_store.instance_of? Array
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ module Rails
2
+ class Application
3
+ module Bootstrap
4
+ initializer :initialize_multi_cache, after: :initialize_cache, group: :all do
5
+ config.cache_store_names.each do |name|
6
+ next if name == :default
7
+ Rails.cache = {
8
+ name: name,
9
+ cache: ActiveSupport::Cache.lookup_store(config.cache_store(name))
10
+ }
11
+
12
+ if Rails.cache(name).respond_to?(:middleware)
13
+ config.middleware.insert_before("Rack::Runtime", Rails.cache(name).middleware)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ module Rails
2
+ class << self
3
+ def cache=(cache_obj)
4
+ @cache = {} unless defined? @cache
5
+ case cache_obj
6
+ when Hash
7
+ key = cache_obj[:name]
8
+ @cache[key] = cache_obj[:cache]
9
+ else
10
+ @cache[:default] = cache_obj
11
+ end
12
+ nil
13
+ end
14
+
15
+ def cache(name = :default)
16
+ return nil unless defined? @cache
17
+ @cache[name]
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module MultiCache
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ require 'multi_cache/version'
2
+ require 'rails'
3
+ require 'multi_cache/rails/application/configuration'
4
+ require 'multi_cache/rails.rb'
5
+ require 'multi_cache/rails/application/multi_cache_bootstrap'
6
+
7
+
8
+ begin
9
+ require 'pry'
10
+ rescue LoadError
11
+ end
12
+
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'multi_cache/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'multi_cache-rails'
7
+ spec.version = MultiCache::Rails::VERSION
8
+ spec.authors = ['Takashi Uesugi']
9
+ spec.email = ['tksuesg@gmail.com']
10
+ spec.summary = %q{Multiple caches configuration for Ruby On Rails.}
11
+ # spec.description = %q{TODO: Write a longer description. Optional.}
12
+ spec.homepage = 'https://github.com/unlearned/multi-cache-rails'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.6'
21
+ spec.add_development_dependency 'rake'
22
+ spec.add_development_dependency 'rspec'
23
+ spec.add_development_dependency 'pry'
24
+ spec.add_dependency 'railties'
25
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+ describe Rails::Application::Configuration do
3
+ describe '#cache_store' do
4
+ let(:configuration) { Rails::Application::Configuration.new }
5
+
6
+ context 'default' do
7
+ subject { configuration.cache_store }
8
+ it { should eq [:file_store, '/tmp/cache/'] }
9
+ end
10
+
11
+ context 'set the prymary' do
12
+ let(:cache_setting) { [:file_store, '/tmp/cache/test'] }
13
+ subject do
14
+ configuration.cache_store = cache_setting
15
+ configuration.cache_store
16
+ end
17
+ it { should eq cache_setting }
18
+ end
19
+
20
+ context 'set the prymary' do
21
+ let(:cache_setting_secondary) { [:file_store, '/tmp/cache/secondary'] }
22
+ let!(:set) do
23
+ configuration.cache_store = {
24
+ name: :secondary,
25
+ setting: cache_setting_secondary
26
+ }
27
+ end
28
+
29
+ it 'returns caches' do
30
+ expect(configuration.cache_store).to eq [:file_store, '/tmp/cache/']
31
+ expect(configuration.cache_store(:secondary)).to eq cache_setting_secondary
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ describe Rails::Application::Bootstrap do
3
+ describe 'initializer propery run' do
4
+ before do
5
+ class TestMultiCache < Rails::Application
6
+ config.cache_store = {
7
+ name: :secondary,
8
+ setting: :memory_store
9
+ }
10
+ end
11
+ TestMultiCache.initialize!
12
+ end
13
+ it 'returns cache objects with key' do
14
+ expect(Rails.cache.class).to eq ActiveSupport::Cache::FileStore
15
+ expect(Rails.cache(:default).class).to eq ActiveSupport::Cache::FileStore
16
+ expect(Rails.cache(:secondary).class).to eq ActiveSupport::Cache::MemoryStore
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+ module Rails
3
+ describe '.cache' do
4
+ let!(:set1) { Rails.cache = 'cache_object1' }
5
+ let!(:set2) { Rails.cache = { name: :secondary, cache: 'cache_object2' } }
6
+ let!(:set3) { Rails.cache = { name: :tertiary, cache: 'cache_object3' } }
7
+
8
+ it 'retyrns cache object' do
9
+ expect(Rails.cache).to eq 'cache_object1'
10
+ expect(Rails.cache(:default)).to eq 'cache_object1'
11
+ expect(Rails.cache(:secondary)).to eq 'cache_object2'
12
+ expect(Rails.cache(:tertiary)).to eq 'cache_object3'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,93 @@
1
+ require 'multi_cache'
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
6
+ # this file to always be loaded, without a need to explicitly require it in any
7
+ # files.
8
+ #
9
+ # Given that it is always loaded, you are encouraged to keep this file as
10
+ # light-weight as possible. Requiring heavyweight dependencies from this file
11
+ # will add to the boot time of your test suite on EVERY test run, even for an
12
+ # individual file that may not need all of that loaded. Instead, consider making
13
+ # a separate helper file that requires the additional dependencies and performs
14
+ # the additional setup, and require it from the spec files that actually need
15
+ # it.
16
+ #
17
+ # The `.rspec` file also contains a few flags that are not defaults but that
18
+ # users commonly want.
19
+ #
20
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+ RSpec.configure do |config|
22
+ # rspec-expectations config goes here. You can use an alternate
23
+ # assertion/expectation library such as wrong or the stdlib/minitest
24
+ # assertions if you prefer.
25
+ config.expect_with :rspec do |expectations|
26
+ # This option will default to `true` in RSpec 4. It makes the `description`
27
+ # and `failure_message` of custom matchers include text for helper methods
28
+ # defined using `chain`, e.g.:
29
+ # be_bigger_than(2).and_smaller_than(4).description
30
+ # # => "be bigger than 2 and smaller than 4"
31
+ # ...rather than:
32
+ # # => "be bigger than 2"
33
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
+ end
35
+
36
+ # rspec-mocks config goes here. You can use an alternate test double
37
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
38
+ config.mock_with :rspec do |mocks|
39
+ # Prevents you from mocking or stubbing a method that does not exist on
40
+ # a real object. This is generally recommended, and will default to
41
+ # `true` in RSpec 4.
42
+ mocks.verify_partial_doubles = true
43
+ end
44
+
45
+ # The settings below are suggested to provide a good initial experience
46
+ # with RSpec, but feel free to customize to your heart's content.
47
+ =begin
48
+ # These two settings work together to allow you to limit a spec run
49
+ # to individual examples or groups you care about by tagging them with
50
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
51
+ # get run.
52
+ config.filter_run :focus
53
+ config.run_all_when_everything_filtered = true
54
+
55
+ # Limits the available syntax to the non-monkey patched syntax that is
56
+ # recommended. For more details, see:
57
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
58
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
59
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
60
+ config.disable_monkey_patching!
61
+
62
+ # This setting enables warnings. It's recommended, but in some cases may
63
+ # be too noisy due to issues in dependencies.
64
+ config.warnings = true
65
+
66
+ # Many RSpec users commonly either run the entire suite or an individual
67
+ # file, and it's useful to allow more verbose output when running an
68
+ # individual spec file.
69
+ if config.files_to_run.one?
70
+ # Use the documentation formatter for detailed output,
71
+ # unless a formatter has already been configured
72
+ # (e.g. via a command-line flag).
73
+ config.default_formatter = 'doc'
74
+ end
75
+
76
+ # Print the 10 slowest examples and example groups at the
77
+ # end of the spec run, to help surface which specs are running
78
+ # particularly slow.
79
+ config.profile_examples = 10
80
+
81
+ # Run specs in random order to surface order dependencies. If you find an
82
+ # order dependency and want to debug it, you can fix the order by providing
83
+ # the seed, which is printed after each run.
84
+ # --seed 1234
85
+ config.order = :random
86
+
87
+ # Seed global randomization in this process using the `--seed` CLI option.
88
+ # Setting this allows you to use `--seed` to deterministically reproduce
89
+ # test failures related to randomization by passing the same `--seed` value
90
+ # as the one that triggered the failure.
91
+ Kernel.srand config.seed
92
+ =end
93
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: multi_cache-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Takashi Uesugi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: railties
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - tksuesg@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/multi_cache.rb
97
+ - lib/multi_cache/rails.rb
98
+ - lib/multi_cache/rails/application/configuration.rb
99
+ - lib/multi_cache/rails/application/multi_cache_bootstrap.rb
100
+ - lib/multi_cache/version.rb
101
+ - multi_cache-rails.gemspec
102
+ - spec/rails/application/configuration_spec.rb
103
+ - spec/rails/application/multi_cache_bootstrap_spec.rb
104
+ - spec/rails_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: https://github.com/unlearned/multi-cache-rails
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.2.2
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Multiple caches configuration for Ruby On Rails.
130
+ test_files:
131
+ - spec/rails/application/configuration_spec.rb
132
+ - spec/rails/application/multi_cache_bootstrap_spec.rb
133
+ - spec/rails_spec.rb
134
+ - spec/spec_helper.rb