taggable_cache 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +23 -2
- data/README.rdoc +0 -3
- data/lib/taggable_cache.rb +2 -1
- data/lib/taggable_cache/rails/observer.rb +8 -8
- data/lib/taggable_cache/railtie.rb +37 -0
- data/lib/taggable_cache/version.rb +1 -1
- data/spec/internal/app/controller/action_caching_controller.rb +15 -0
- data/spec/internal/app/controller/fragment_caching_controller.rb +8 -0
- data/spec/internal/app/models/simple_observer.rb +2 -0
- data/spec/internal/app/views/fragment_caching/index.html.erb +3 -0
- data/spec/internal/config/initializers/taggable.rb +0 -8
- data/spec/internal/config/routes.rb +1 -1
- data/spec/rails_cache_spec.rb +9 -5
- data/spec/requests/action_caching_controller_spec.rb +28 -0
- data/spec/requests/fragment_caching_controller_spec.rb +28 -0
- data/spec/spec_helper.rb +4 -2
- data/taggable-cache.gemspec +2 -1
- metadata +23 -10
- data/.document +0 -5
- data/config.ru +0 -7
- data/lib/taggable_cache/rails.rb +0 -5
- data/lib/taggable_cache/rails/cache.rb +0 -15
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
taggable_cache (0.
|
5
|
-
|
4
|
+
taggable_cache (0.2.0)
|
5
|
+
rails (>= 3.0.8)
|
6
|
+
redis (>= 2.2.2)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: http://rubygems.org/
|
@@ -36,12 +37,22 @@ GEM
|
|
36
37
|
multi_json (~> 1.0)
|
37
38
|
arel (3.0.0)
|
38
39
|
builder (3.0.0)
|
40
|
+
capybara (1.1.2)
|
41
|
+
mime-types (>= 1.16)
|
42
|
+
nokogiri (>= 1.3.3)
|
43
|
+
rack (>= 1.0.0)
|
44
|
+
rack-test (>= 0.5.4)
|
45
|
+
selenium-webdriver (~> 2.0)
|
46
|
+
xpath (~> 0.1.4)
|
47
|
+
childprocess (0.3.1)
|
48
|
+
ffi (~> 1.0.6)
|
39
49
|
coderay (0.9.8)
|
40
50
|
combustion (0.3.1)
|
41
51
|
rails (>= 3.1.0)
|
42
52
|
thor (>= 0.14.6)
|
43
53
|
diff-lcs (1.1.3)
|
44
54
|
erubis (2.7.0)
|
55
|
+
ffi (1.0.11)
|
45
56
|
hike (1.2.1)
|
46
57
|
i18n (0.6.0)
|
47
58
|
journey (1.0.1)
|
@@ -54,6 +65,7 @@ GEM
|
|
54
65
|
ruby_parser (>= 2.3.1)
|
55
66
|
mime-types (1.17.2)
|
56
67
|
multi_json (1.0.4)
|
68
|
+
nokogiri (1.5.0)
|
57
69
|
polyglot (0.3.3)
|
58
70
|
pry (0.9.7.4)
|
59
71
|
coderay (~> 0.9.8)
|
@@ -101,6 +113,12 @@ GEM
|
|
101
113
|
rspec (~> 2.8.0)
|
102
114
|
ruby_parser (2.3.1)
|
103
115
|
sexp_processor (~> 3.0)
|
116
|
+
rubyzip (0.9.6.1)
|
117
|
+
selenium-webdriver (2.19.0)
|
118
|
+
childprocess (>= 0.2.5)
|
119
|
+
ffi (~> 1.0.9)
|
120
|
+
multi_json (~> 1.0.4)
|
121
|
+
rubyzip
|
104
122
|
sexp_processor (3.0.10)
|
105
123
|
slop (2.1.0)
|
106
124
|
sprockets (2.1.2)
|
@@ -114,11 +132,14 @@ GEM
|
|
114
132
|
polyglot
|
115
133
|
polyglot (>= 0.3.1)
|
116
134
|
tzinfo (0.3.31)
|
135
|
+
xpath (0.1.4)
|
136
|
+
nokogiri (~> 1.3)
|
117
137
|
|
118
138
|
PLATFORMS
|
119
139
|
ruby
|
120
140
|
|
121
141
|
DEPENDENCIES
|
142
|
+
capybara
|
122
143
|
combustion (~> 0.3.1)
|
123
144
|
pry
|
124
145
|
rspec
|
data/README.rdoc
CHANGED
@@ -8,14 +8,11 @@ See example in spec/internal.
|
|
8
8
|
|
9
9
|
== Build Status {<img src="https://secure.travis-ci.org/brain-geek/taggable-cache.png"/>}[http://travis-ci.org/brain-geek/taggable-cache]
|
10
10
|
|
11
|
-
== Dependency Status {<img src="https://gemnasium.com/brain-geek/taggable-cache.png?travis"/>}[https://gemnasium.com/brain-geek/taggable-cache]
|
12
|
-
|
13
11
|
== Contributing to taggable-cache
|
14
12
|
|
15
13
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
16
14
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
17
15
|
* Fork the project.
|
18
|
-
* Start a feature/bugfix branch.
|
19
16
|
* Commit and push until you are happy with your contribution.
|
20
17
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
21
18
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
data/lib/taggable_cache.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
Rails.cache.
|
1
|
+
module TaggableCache::Rails
|
2
|
+
class Observer < ActiveRecord::Observer
|
3
|
+
def event(model)
|
4
|
+
Rails.cache.delete_by_tags(model, model.class)
|
5
5
|
end
|
6
|
-
end
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
alias :after_update :event
|
8
|
+
alias :after_destroy :event
|
9
|
+
alias :after_create :event
|
10
|
+
end
|
11
11
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
ActiveSupport::Cache::Store.class_eval do
|
2
|
+
def taggable
|
3
|
+
@taggable ||= ::TaggableCache::Store.new
|
4
|
+
end
|
5
|
+
|
6
|
+
alias_method :original_write, :write
|
7
|
+
|
8
|
+
def write(name, value, options = nil)
|
9
|
+
if !options.nil? && options.has_key?(:depends_on)
|
10
|
+
add_tags(name, *options[:depends_on])
|
11
|
+
end
|
12
|
+
|
13
|
+
original_write(name, value, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_tags(key, *params)
|
17
|
+
taggable.add(key, *params)
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete_by_tags(*params)
|
21
|
+
taggable.get(*params).each do |m|
|
22
|
+
self.delete(m)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
ActionController::Base.class_eval do
|
28
|
+
def depends_on(*params)
|
29
|
+
key_name = fragment_cache_key(::ActionController::Caching::Actions::ActionCachePath.new(self).path)
|
30
|
+
Rails.cache.add_tags(key_name, *params)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module TaggableCache
|
35
|
+
class Railtie < ::Rails::Railtie
|
36
|
+
end
|
37
|
+
end
|
@@ -1,11 +1,3 @@
|
|
1
|
-
#combustion uses rails file cache, so we make magic on it
|
2
|
-
require 'taggable_cache/rails'
|
3
|
-
|
4
|
-
ActiveSupport::Cache::FileStore.class_eval do
|
5
|
-
include TaggableCache::Rails::Cache
|
6
|
-
end
|
7
|
-
|
8
1
|
#Listing all models with enabled taggable cache
|
9
|
-
# TaggableCache::Rails::Observer.observe Page
|
10
2
|
|
11
3
|
Combustion::Application.config.active_record.observers = :simple_observer
|
data/spec/rails_cache_spec.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'spec_helper.rb')
|
2
2
|
|
3
|
-
describe TaggableCache::Rails::Cache do
|
3
|
+
describe 'TaggableCache::Rails::Cache' do
|
4
4
|
before :all do
|
5
5
|
@object = TaggableCache::Store.new
|
6
6
|
Redis.new.flushall
|
7
|
+
@page_object = Page.create
|
8
|
+
end
|
7
9
|
|
8
|
-
|
10
|
+
before :each do
|
11
|
+
Rails.cache.delete 'key'
|
12
|
+
Rails.cache.delete 'lorem'
|
9
13
|
end
|
10
14
|
|
11
15
|
describe "taggable hooked on Rails.cache.write" do
|
12
16
|
it "adds key to store" do
|
13
|
-
Rails.cache.write
|
17
|
+
Rails.cache.write('key', 'value', :depends_on => [@page_object])
|
14
18
|
|
15
19
|
@object.get(@page_object).should == ['key']
|
16
20
|
end
|
@@ -18,7 +22,7 @@ describe TaggableCache::Rails::Cache do
|
|
18
22
|
|
19
23
|
describe "taggable hooked as observer" do
|
20
24
|
it "detects object change" do
|
21
|
-
Rails.cache.write
|
25
|
+
Rails.cache.write('key', 'value', :depends_on => [@page_object])
|
22
26
|
|
23
27
|
Rails.cache.read('key').should == 'value'
|
24
28
|
|
@@ -30,7 +34,7 @@ describe TaggableCache::Rails::Cache do
|
|
30
34
|
end
|
31
35
|
|
32
36
|
it "detects model change" do
|
33
|
-
Rails.cache.write
|
37
|
+
Rails.cache.write('lorem', 'impsum', :depends_on => [Page])
|
34
38
|
|
35
39
|
Rails.cache.read('lorem').should == 'impsum'
|
36
40
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActionCachingController do
|
4
|
+
before :each do
|
5
|
+
get 'action_caching/expire'
|
6
|
+
@url = 'action_caching/index'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should be successful" do
|
10
|
+
Page.should_receive :load_lot_of_data
|
11
|
+
get @url
|
12
|
+
response.status.should be(200)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should run second test without cache" do
|
16
|
+
Page.should_receive(:load_lot_of_data).once
|
17
|
+
get @url
|
18
|
+
response.status.should be(200)
|
19
|
+
|
20
|
+
get @url
|
21
|
+
response.status.should be(200)
|
22
|
+
|
23
|
+
Page.should_receive(:load_lot_of_data).once
|
24
|
+
Page.create
|
25
|
+
get @url
|
26
|
+
response.status.should be(200)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FragmentCachingController do
|
4
|
+
before :each do
|
5
|
+
get 'fragment_caching/expire'
|
6
|
+
@url = 'fragment_caching/index'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should be successful" do
|
10
|
+
Page.should_receive :load_lot_of_data
|
11
|
+
get @url
|
12
|
+
response.status.should be(200)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should run second test without cache" do
|
16
|
+
Page.should_receive(:load_lot_of_data).once
|
17
|
+
get @url
|
18
|
+
response.status.should be(200)
|
19
|
+
|
20
|
+
get @url
|
21
|
+
response.status.should be(200)
|
22
|
+
|
23
|
+
Page.should_receive(:load_lot_of_data).once
|
24
|
+
Page.create
|
25
|
+
get @url
|
26
|
+
response.status.should be(200)
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler'
|
3
|
-
require 'taggable_cache'
|
4
|
-
|
5
3
|
Bundler.require :default, :development
|
6
4
|
|
5
|
+
require 'capybara/rspec'
|
6
|
+
|
7
7
|
Combustion.initialize!
|
8
8
|
|
9
9
|
require 'rspec/rails'
|
10
|
+
require 'capybara/rails'
|
11
|
+
require 'taggable_cache/railtie'
|
10
12
|
|
11
13
|
RSpec.configure do |config|
|
12
14
|
config.use_transactional_fixtures = true
|
data/taggable-cache.gemspec
CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.rubygems_version = "1.8.15"
|
29
29
|
s.summary = "This gem simplifies cache expiration in rails by providing depends_on option to rails cache."
|
30
30
|
|
31
|
-
s.add_dependency(%q<
|
31
|
+
s.add_dependency(%q<rails>, [">= 3.0.8"])
|
32
|
+
s.add_dependency(%q<redis>, [">= 2.2.2"])
|
32
33
|
end
|
33
34
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taggable_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,17 +11,28 @@ bindir: bin
|
|
11
11
|
cert_chain: []
|
12
12
|
date: 2012-02-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &72497550 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.8
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *72497550
|
14
25
|
- !ruby/object:Gem::Dependency
|
15
26
|
name: redis
|
16
|
-
requirement: &
|
27
|
+
requirement: &72496880 !ruby/object:Gem::Requirement
|
17
28
|
none: false
|
18
29
|
requirements:
|
19
30
|
- - ! '>='
|
20
31
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
32
|
+
version: 2.2.2
|
22
33
|
type: :runtime
|
23
34
|
prerelease: false
|
24
|
-
version_requirements: *
|
35
|
+
version_requirements: *72496880
|
25
36
|
description: This gem simplifies cache expiration in rails
|
26
37
|
email: brain-geek@yandex.ua
|
27
38
|
executables: []
|
@@ -30,7 +41,6 @@ extra_rdoc_files:
|
|
30
41
|
- LICENSE.txt
|
31
42
|
- README.rdoc
|
32
43
|
files:
|
33
|
-
- .document
|
34
44
|
- .gitignore
|
35
45
|
- .travis.yml
|
36
46
|
- Gemfile
|
@@ -38,15 +48,16 @@ files:
|
|
38
48
|
- LICENSE.txt
|
39
49
|
- README.rdoc
|
40
50
|
- Rakefile
|
41
|
-
- config.ru
|
42
51
|
- lib/taggable_cache.rb
|
43
|
-
- lib/taggable_cache/rails.rb
|
44
|
-
- lib/taggable_cache/rails/cache.rb
|
45
52
|
- lib/taggable_cache/rails/observer.rb
|
53
|
+
- lib/taggable_cache/railtie.rb
|
46
54
|
- lib/taggable_cache/store.rb
|
47
55
|
- lib/taggable_cache/version.rb
|
56
|
+
- spec/internal/app/controller/action_caching_controller.rb
|
57
|
+
- spec/internal/app/controller/fragment_caching_controller.rb
|
48
58
|
- spec/internal/app/models/page.rb
|
49
59
|
- spec/internal/app/models/simple_observer.rb
|
60
|
+
- spec/internal/app/views/fragment_caching/index.html.erb
|
50
61
|
- spec/internal/config/database.yml
|
51
62
|
- spec/internal/config/initializers/taggable.rb
|
52
63
|
- spec/internal/config/routes.rb
|
@@ -54,6 +65,8 @@ files:
|
|
54
65
|
- spec/internal/public/favicon.ico
|
55
66
|
- spec/models/page_spec.rb
|
56
67
|
- spec/rails_cache_spec.rb
|
68
|
+
- spec/requests/action_caching_controller_spec.rb
|
69
|
+
- spec/requests/fragment_caching_controller_spec.rb
|
57
70
|
- spec/spec_helper.rb
|
58
71
|
- spec/taggable-cache/store_spec.rb
|
59
72
|
- taggable-cache.gemspec
|
@@ -72,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
85
|
version: '0'
|
73
86
|
segments:
|
74
87
|
- 0
|
75
|
-
hash:
|
88
|
+
hash: -828411823
|
76
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
90
|
none: false
|
78
91
|
requirements:
|
@@ -81,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
94
|
version: '0'
|
82
95
|
segments:
|
83
96
|
- 0
|
84
|
-
hash:
|
97
|
+
hash: -828411823
|
85
98
|
requirements: []
|
86
99
|
rubyforge_project:
|
87
100
|
rubygems_version: 1.8.15
|
data/.document
DELETED
data/config.ru
DELETED
data/lib/taggable_cache/rails.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module TaggableCache::Rails::Cache
|
2
|
-
def taggable
|
3
|
-
@taggable ||= ::TaggableCache::Store.new
|
4
|
-
end
|
5
|
-
|
6
|
-
def write(name, value, options = nil)
|
7
|
-
if !options.nil? && options.has_key?(:depends_on)
|
8
|
-
taggable.add(name, *options[:depends_on])
|
9
|
-
#@taggable.
|
10
|
-
options.delete(:depends_on)
|
11
|
-
end
|
12
|
-
|
13
|
-
super(name, value, options)
|
14
|
-
end
|
15
|
-
end
|