cached_key_value_store 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cached-key-value-store (0.0.0)
5
+ activesupport
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activesupport (3.2.13)
11
+ i18n (= 0.6.1)
12
+ multi_json (~> 1.0)
13
+ diff-lcs (1.1.3)
14
+ i18n (0.6.1)
15
+ multi_json (1.7.2)
16
+ rspec (2.12.0)
17
+ rspec-core (~> 2.12.0)
18
+ rspec-expectations (~> 2.12.0)
19
+ rspec-mocks (~> 2.12.0)
20
+ rspec-core (2.12.2)
21
+ rspec-expectations (2.12.1)
22
+ diff-lcs (~> 1.1.3)
23
+ rspec-mocks (2.12.1)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ cached-key-value-store!
30
+ rspec (~> 2.6)
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Michael Wheeler
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,29 @@
1
+ # CachedKeyValueStore
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'cached_key_value_store'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cached_key_value_store
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+ require 'cached_key_value_store/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'cached_key_value_store'
6
+ s.version = CachedKeyValueStore::VERSION
7
+ s.summary = 'An I18n Backend with in-memory cacheing'
8
+ s.description = %q{This gem is designed for usage with a key-value store
9
+ database, where latency is an issue. Locale changes are
10
+ versioned to allow for an easy cache-bust. }
11
+ s.authors = ['Mike Wheeler']
12
+ s.email = 'mwheeler@g2crowd.com'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+ s.homepage = 'http://rubygems.org/gems/cached-key-value-store'
19
+
20
+ s.add_dependency "activesupport"
21
+ s.add_development_dependency "rspec", "~> 2.6"
22
+ end
@@ -0,0 +1,3 @@
1
+ module CachedKeyValueStore
2
+ VERSION = '0.0.0'
3
+ end
@@ -0,0 +1 @@
1
+ require 'i18n/backend/cached_key_value_store'
@@ -0,0 +1,35 @@
1
+ module I18n
2
+ module Backend
3
+ class CachedKeyValueStore < KeyValue
4
+ include Memoize
5
+
6
+ KEY_PREFIX = 'i18n:locale_version:'
7
+
8
+ def store_translations(locale, data, options = {})
9
+ update_version! locale
10
+ super
11
+ end
12
+
13
+ def ensure_freshness!(locale)
14
+ current = current_version locale
15
+
16
+ if last_version[locale] != current
17
+ reset_memoizations! locale
18
+ last_version[locale] = current
19
+ end
20
+ end
21
+
22
+ def last_version
23
+ @last_version ||= {}
24
+ end
25
+
26
+ def update_version!(locale)
27
+ @store["#{KEY_PREFIX}#{locale}"] = Time.now.to_i
28
+ end
29
+
30
+ def current_version(locale)
31
+ @store["#{KEY_PREFIX}#{locale}"]
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe I18n::Backend::CachedKeyValueStore do
4
+ let(:store) { {} }
5
+ subject { I18n::Backend::CachedKeyValueStore.new(store) }
6
+
7
+ describe '#ensure_freshness!' do
8
+ context 'with expired locale' do
9
+ before do
10
+ store['i18n:locale_version:en'] = '2'
11
+ end
12
+
13
+ it 'calls reset_memoizations!' do
14
+ subject.should_receive(:reset_memoizations!).with(:en)
15
+ subject.ensure_freshness! :en
16
+ end
17
+
18
+ it 'updates last_locale' do
19
+ subject.ensure_freshness! :en
20
+ subject.last_version.should == { en: '2' }
21
+ end
22
+ end
23
+
24
+ context 'with current locale' do
25
+ before do
26
+ store['i18n:locale_version:en'] = '1'
27
+ subject.last_version[:en] = '1'
28
+ end
29
+
30
+ it 'does not call reset_memoizations!' do
31
+ subject.should_not_receive(:reset_memoizations!)
32
+ subject.ensure_freshness! :en
33
+ end
34
+
35
+ it 'maintains last_locale' do
36
+ subject.ensure_freshness! :en
37
+ subject.last_version.should == { en: '1' }
38
+ end
39
+ end
40
+ end
41
+
42
+ describe 'store_translations' do
43
+ before do
44
+ store['i18n:locale_version:en'] = '2'
45
+ end
46
+
47
+ it 'updates and dememoizes' do
48
+ subject.should_receive(:reset_memoizations!).with(:en)
49
+ subject.store_translations(:en, {simple: 'test'})
50
+ subject.current_version(:en).should_not == '2'
51
+ store['en.simple'].should match(/test/)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,2 @@
1
+ require 'i18n'
2
+ require 'i18n/backend/cached_key_value_store'
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cached_key_value_store
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mike Wheeler
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.6'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.6'
46
+ description: ! "This gem is designed for usage with a key-value store\n database,
47
+ where latency is an issue. Locale changes are\n versioned
48
+ to allow for an easy cache-bust. "
49
+ email: mwheeler@g2crowd.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - Gemfile.lock
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - cached_key_value_store.gemspec
61
+ - lib/cached_key_value_store.rb
62
+ - lib/cached_key_value_store/version.rb
63
+ - lib/i18n/backend/cached_key_value_store.rb
64
+ - spec/i18n/backend/cached_key_value_store_spec.rb
65
+ - spec/spec_helper.rb
66
+ homepage: http://rubygems.org/gems/cached-key-value-store
67
+ licenses: []
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.24
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: An I18n Backend with in-memory cacheing
90
+ test_files:
91
+ - spec/i18n/backend/cached_key_value_store_spec.rb
92
+ - spec/spec_helper.rb