dalli-store-extensions 0.0.2

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.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'activesupport'
4
+ gem 'rspec'
5
+ gem 'dalli'
6
+ gem 'i18n'
data/README.rdoc ADDED
@@ -0,0 +1,20 @@
1
+ == Dalli Storage Extensions
2
+
3
+ The dalli-store-extensions plugin for Rails 3 adds support for match-based deletes while using the dalli storage engine.
4
+
5
+ === Installation
6
+
7
+ In your Gemfile, make sure you have dalli and this gem:
8
+
9
+ gem 'dalli'
10
+ gem 'dalli-store-extensions', :git => "git://github.com/defconomicron/dalli-store-extensions.git"
11
+
12
+ In your config/environments/X.rb, where X is the name of the environment where you'd like to enable caching, make sure you are using the dalli storage engine:
13
+
14
+ config.cache_store = :dalli_store
15
+
16
+ You now use standard rails caching mechanisms. To expire a fragment:
17
+
18
+ expire_fragment /.*search.*/
19
+
20
+ Where the regular expression matches the fragment cache path.
@@ -0,0 +1,36 @@
1
+ require 'active_support/cache/dalli_store'
2
+ require 'active_support/core_ext/module/aliasing'
3
+ require 'keyset'
4
+
5
+ class ActiveSupport::Cache::DalliStore
6
+ @@key = "delete_matched_support_key"
7
+
8
+ def write_entry_with_match_support(key, entry, options)
9
+ keys.add(key)
10
+ write_entry_without_match_support(key, entry, options)
11
+ end
12
+ alias_method_chain :write_entry, :match_support
13
+
14
+ def clear_with_match_support(options=nil)
15
+ keys.clear
16
+ clear_without_match_support(options)
17
+ end
18
+ alias_method_chain :clear, :match_support
19
+
20
+ def delete_entry_with_match_support(key, options)
21
+ keys.delete key
22
+ delete_entry_without_match_support(key, options)
23
+ end
24
+ alias_method_chain :delete_entry, :match_support
25
+
26
+ def delete_matched(matcher, options=nil)
27
+ keys.each do |key|
28
+ delete_entry(key, options) if key =~ matcher
29
+ end
30
+ end
31
+
32
+ def keys
33
+ @keys ||= KeySet.new(self, @@key)
34
+ end
35
+ end
36
+
data/lib/keyset.rb ADDED
@@ -0,0 +1,44 @@
1
+ require 'active_support/core_ext/module/aliasing'
2
+
3
+ class KeySet < Set
4
+ def initialize(store, store_key)
5
+ @store = store
6
+ @store_key = store_key
7
+
8
+
9
+ if existing=@store.send(:read_entry, @store_key, {})
10
+ super(YAML.load(existing.value))
11
+ else
12
+ super([])
13
+ end
14
+
15
+ end
16
+
17
+ def add_with_cache(value)
18
+ add_without_cache(value)
19
+ ensure
20
+ store
21
+ end
22
+
23
+ alias_method_chain :add, :cache
24
+
25
+ def delete_with_cache(value)
26
+ delete_without_cache(value)
27
+ ensure
28
+ store
29
+ end
30
+
31
+ alias_method_chain :delete, :cache
32
+
33
+ def clear_with_cache
34
+ clear_without_cache
35
+ ensure
36
+ store
37
+ end
38
+
39
+ alias_method_chain :clear, :cache
40
+ private
41
+ def store
42
+ @store.send(:write_entry_without_match_support, @store_key, self.to_a.to_yaml, {})
43
+ end
44
+ end
@@ -0,0 +1,45 @@
1
+ require "#{File.dirname(__FILE__)}/spec_helper"
2
+
3
+
4
+ describe ActiveSupport::Cache::DalliStore do
5
+ before(:all) do
6
+ @cache = ActiveSupport::Cache.lookup_store(:dalli_store, "localhost:11211")
7
+
8
+ @data = {
9
+ "color1" => "red",
10
+ "color2" => "blue"
11
+ }
12
+
13
+ @data.each do |k,v|
14
+ @cache.delete(k)
15
+ end
16
+ end
17
+
18
+ it "should write and read value from cache" do
19
+ @data.each do |k,v|
20
+ @cache.write(k,v)
21
+ end
22
+
23
+ @data.each do |k,v|
24
+ @cache.fetch(k).should eql(v)
25
+ end
26
+ end
27
+
28
+ it "should successfully expire a cache key on a match" do
29
+ @data.each do |k,v|
30
+ @cache.write(k,v)
31
+ end
32
+
33
+ @cache.delete_matched(/color.*/)
34
+
35
+ @data.each do |k,v|
36
+ @cache.fetch(k).should eql(nil)
37
+ end
38
+ end
39
+
40
+ it "should not expire a cache key without a match" do
41
+ @cache.write("permanent", "value")
42
+ @cache.delete_matched(/notpermanent.*/)
43
+ @cache.fetch("permanent").should eql("value")
44
+ end
45
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'active_support/cache'
4
+ require 'active_support/cache/dalli_store'
5
+
6
+ require File.join(File.dirname(__FILE__), "../init.rb")
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dalli-store-extensions
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - James Kassemi
14
+ autorequire: builder
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-05-29 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Provides delete_matched for Dalli store in Rails 3
22
+ email: jkassemi@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - Gemfile
29
+ - README.rdoc
30
+ files:
31
+ - lib/keyset.rb
32
+ - lib/dalli-store-extensions.rb
33
+ - spec/spec_helper.rb
34
+ - spec/cache_spec.rb
35
+ - Gemfile
36
+ - README.rdoc
37
+ homepage: http://tweekedideas.com
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --title
43
+ - dalli-store-extensions -- matched deletion
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ hash: 3
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.24
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Rails Dalli Store extensions providing matched deletion
71
+ test_files: []
72
+
73
+ has_rdoc: false