catche 0.2.4 → 0.2.5
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/README.md +29 -1
- data/lib/catche.rb +6 -5
- data/lib/catche/controller.rb +0 -2
- data/lib/catche/model.rb +0 -2
- data/lib/catche/railtie.rb +3 -1
- data/lib/catche/version.rb +1 -1
- data/lib/catche/view_helpers.rb +37 -0
- metadata +15 -14
data/README.md
CHANGED
@@ -9,6 +9,10 @@ Add this to your Gemfile and run `bundle`.
|
|
9
9
|
gem "catche"
|
10
10
|
```
|
11
11
|
|
12
|
+
## Troubleshooting
|
13
|
+
|
14
|
+
This gem is still in beta (v0.x), this means that certain structures, especially storing data, may change. If you're experiencing problems please try clearing the cache using `Rails.cache.clear`. If that doesn't work please open up a new issue.
|
15
|
+
|
12
16
|
## Controller caching
|
13
17
|
|
14
18
|
Catche supports both action and page caching using the Rails methods `caches_action` and `caches_page`.
|
@@ -145,6 +149,30 @@ class Task < ActiveRecord::Base
|
|
145
149
|
end
|
146
150
|
```
|
147
151
|
|
152
|
+
## View caching
|
153
|
+
|
154
|
+
Catche supports view caching using the Rails methods `cache`.
|
155
|
+
|
156
|
+
### Resource caching
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
<% catche @project do %>
|
160
|
+
<%= @project.title %>
|
161
|
+
<% end %>
|
162
|
+
```
|
163
|
+
|
164
|
+
### Collection caching
|
165
|
+
|
166
|
+
Because a collection may be an array, you will need to pass along the configured model you wish to use;
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
<% catche @projects, :model => Project do %>
|
170
|
+
<% @projects.each do |project| %>
|
171
|
+
<%= project.title %>
|
172
|
+
<% end %>
|
173
|
+
<% end %>
|
174
|
+
```
|
175
|
+
|
148
176
|
## How does it work?
|
149
177
|
|
150
178
|
Catche intercepts a cached value and tags this value using the unique identifier for the given/loaded resource or collection. Once a resource expires it will expire the tagged cached values, such as the resource itself and the collection it belongs to.
|
@@ -176,7 +204,7 @@ Want support for more? Just fork and open up a pull request.
|
|
176
204
|
|
177
205
|
## Roadmap
|
178
206
|
|
179
|
-
|
207
|
+
No features planned for now. In need of a feature? Please open up an issue, or pull request.
|
180
208
|
|
181
209
|
## License
|
182
210
|
|
data/lib/catche.rb
CHANGED
@@ -5,17 +5,18 @@ require 'catche/model'
|
|
5
5
|
require 'catche/tag'
|
6
6
|
require 'catche/resource_loader'
|
7
7
|
require 'catche/expire'
|
8
|
+
require 'catche/view_helpers'
|
8
9
|
|
9
10
|
module Catche
|
10
11
|
|
11
12
|
extend self
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
class << self
|
15
|
+
|
16
|
+
def adapter
|
17
|
+
Catche::Adapter::Base
|
18
|
+
end
|
16
19
|
|
17
|
-
def adapter
|
18
|
-
Catche::Adapter::Base
|
19
20
|
end
|
20
21
|
|
21
22
|
end
|
data/lib/catche/controller.rb
CHANGED
data/lib/catche/model.rb
CHANGED
data/lib/catche/railtie.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module Catche
|
2
2
|
class Railtie < ::Rails::Railtie
|
3
3
|
initializer "include.catche" do |app|
|
4
|
-
Catche
|
4
|
+
ActionController::Base.send :include, Catche::Controller
|
5
|
+
ActiveRecord::Base.send :include, Catche::Model
|
6
|
+
ActionView::Base.send :include, Catche::ViewHelpers
|
5
7
|
end
|
6
8
|
end
|
7
9
|
end
|
data/lib/catche/version.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Catche
|
2
|
+
module ViewHelpers
|
3
|
+
|
4
|
+
# Caches a fragment
|
5
|
+
# See ActionView `cache` for more information
|
6
|
+
#
|
7
|
+
# <% catche @project do %>
|
8
|
+
# <%= @project.title %>
|
9
|
+
# <% end %>
|
10
|
+
#
|
11
|
+
# <% catche @projects, :model => Project do %>
|
12
|
+
# <% @projects.each do |project| %>
|
13
|
+
# <%= project.title %>
|
14
|
+
# <% end %>
|
15
|
+
# <% end %>
|
16
|
+
def catche(model_or_resource, options={}, &block)
|
17
|
+
tags = []
|
18
|
+
name = Catche::Tag.join 'fragment', model_or_resource.hash
|
19
|
+
key = ActiveSupport::Cache.expand_cache_key name, :views
|
20
|
+
object = options[:model] || model_or_resource
|
21
|
+
|
22
|
+
if object.respond_to?(:catche_tag)
|
23
|
+
if object.respond_to?(:new)
|
24
|
+
tags = Catche::Tag::Collect.collection(controller, object)[:set]
|
25
|
+
else
|
26
|
+
tags = Catche::Tag::Collect.resource(object)[:set]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Catche::Tag.tag_view! key, *tags if tags.any?
|
31
|
+
|
32
|
+
cache name, options, &block
|
33
|
+
end
|
34
|
+
alias :catches_fragment :catche
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: catche
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06
|
12
|
+
date: 2012-07-06 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70289602354040 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.2.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70289602354040
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sqlite3
|
27
|
-
requirement: &
|
27
|
+
requirement: &70289592727760 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70289592727760
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec-rails
|
38
|
-
requirement: &
|
38
|
+
requirement: &70289592727300 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70289592727300
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: capybara
|
49
|
-
requirement: &
|
49
|
+
requirement: &70289592726880 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70289592726880
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: guard-rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &70289592726460 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70289592726460
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: guard-spork
|
71
|
-
requirement: &
|
71
|
+
requirement: &70289592726040 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70289592726040
|
80
80
|
description: ''
|
81
81
|
email:
|
82
82
|
- mail@arjen.me
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- lib/catche/tag/collect.rb
|
99
99
|
- lib/catche/tag.rb
|
100
100
|
- lib/catche/version.rb
|
101
|
+
- lib/catche/view_helpers.rb
|
101
102
|
- lib/catche.rb
|
102
103
|
- lib/tasks/catche_tasks.rake
|
103
104
|
- MIT-LICENSE
|