cache_fu 0.1.3 → 0.1.4
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 +3 -0
- data/defaults/memcached.yml.default +1 -3
- data/lib/cache_fu.rb +0 -2
- metadata +4 -25
- data/lib/acts_as_cached/fragment_cache.rb +0 -102
- data/lib/acts_as_cached/local_cache.rb +0 -44
data/README
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
A rewrite of acts_as_cached.
|
4
4
|
This version is only compatible with rails 3 and above.
|
5
5
|
|
6
|
+
For fragment and page caching use Rails inbuilt MemCacheStore as it already provides all the functionality.
|
7
|
+
This gem is very useful for caching in models.
|
8
|
+
|
6
9
|
== Changes from acts_as_cached 1
|
7
10
|
|
8
11
|
- You can no longer set a 'ttl' method on a class. Instead,
|
@@ -7,8 +7,6 @@ defaults:
|
|
7
7
|
debug: false
|
8
8
|
namespace: app
|
9
9
|
sessions: false
|
10
|
-
session_servers: false
|
11
|
-
fragments: false
|
12
10
|
memory: 64
|
13
11
|
servers: localhost:11211
|
14
12
|
benchmarking: true
|
@@ -22,7 +20,7 @@ development:
|
|
22
20
|
servers: localhost:11211
|
23
21
|
|
24
22
|
# turn off caching
|
25
|
-
test:
|
23
|
+
test:
|
26
24
|
disabled: true
|
27
25
|
|
28
26
|
production:
|
data/lib/cache_fu.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/acts_as_cached/config'
|
2
2
|
require File.dirname(__FILE__) + '/acts_as_cached/cache_methods'
|
3
|
-
require File.dirname(__FILE__) + '/acts_as_cached/fragment_cache'
|
4
3
|
require File.dirname(__FILE__) + '/acts_as_cached/benchmarking'
|
5
4
|
require File.dirname(__FILE__) + '/acts_as_cached/disabled'
|
6
|
-
require File.dirname(__FILE__) + '/acts_as_cached/local_cache'
|
7
5
|
require File.dirname(__FILE__) + '/acts_as_cached/railtie' if defined?(Rails::Railtie)
|
8
6
|
|
9
7
|
module ActsAsCached
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cache_fu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 3
|
10
|
-
version: 0.1.3
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.4
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Surendra Singhi
|
@@ -15,7 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-
|
13
|
+
date: 2011-06-14 00:00:00 +05:30
|
19
14
|
default_executable:
|
20
15
|
dependencies:
|
21
16
|
- !ruby/object:Gem::Dependency
|
@@ -26,10 +21,6 @@ dependencies:
|
|
26
21
|
requirements:
|
27
22
|
- - ~>
|
28
23
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 7
|
30
|
-
segments:
|
31
|
-
- 3
|
32
|
-
- 0
|
33
24
|
version: "3.0"
|
34
25
|
type: :runtime
|
35
26
|
version_requirements: *id001
|
@@ -41,10 +32,6 @@ dependencies:
|
|
41
32
|
requirements:
|
42
33
|
- - ~>
|
43
34
|
- !ruby/object:Gem::Version
|
44
|
-
hash: 7
|
45
|
-
segments:
|
46
|
-
- 3
|
47
|
-
- 0
|
48
35
|
version: "3.0"
|
49
36
|
type: :development
|
50
37
|
version_requirements: *id002
|
@@ -62,8 +49,6 @@ files:
|
|
62
49
|
- lib/acts_as_cached/cache_methods.rb
|
63
50
|
- lib/acts_as_cached/config.rb
|
64
51
|
- lib/acts_as_cached/disabled.rb
|
65
|
-
- lib/acts_as_cached/fragment_cache.rb
|
66
|
-
- lib/acts_as_cached/local_cache.rb
|
67
52
|
- lib/acts_as_cached/railtie.rb
|
68
53
|
- lib/acts_as_cached/recipes.rb
|
69
54
|
- lib/cache_fu.rb
|
@@ -97,23 +82,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
82
|
requirements:
|
98
83
|
- - ">="
|
99
84
|
- !ruby/object:Gem::Version
|
100
|
-
hash: 3
|
101
|
-
segments:
|
102
|
-
- 0
|
103
85
|
version: "0"
|
104
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
87
|
none: false
|
106
88
|
requirements:
|
107
89
|
- - ">="
|
108
90
|
- !ruby/object:Gem::Version
|
109
|
-
hash: 3
|
110
|
-
segments:
|
111
|
-
- 0
|
112
91
|
version: "0"
|
113
92
|
requirements: []
|
114
93
|
|
115
94
|
rubyforge_project:
|
116
|
-
rubygems_version: 1.
|
95
|
+
rubygems_version: 1.6.2
|
117
96
|
signing_key:
|
118
97
|
specification_version: 3
|
119
98
|
summary: Makes caching easy for ActiveRecord models
|
@@ -1,102 +0,0 @@
|
|
1
|
-
module ActsAsCached
|
2
|
-
module FragmentCache
|
3
|
-
def self.setup!
|
4
|
-
class << CACHE
|
5
|
-
include Extensions
|
6
|
-
end
|
7
|
-
|
8
|
-
setup_fragment_cache_cache
|
9
|
-
setup_rails_for_memcache_fragments
|
10
|
-
setup_rails_for_action_cache_options
|
11
|
-
end
|
12
|
-
|
13
|
-
# add :ttl option to cache helper and set cache store memcache object
|
14
|
-
def self.setup_rails_for_memcache_fragments
|
15
|
-
::ActionController::Base.cache_store = CACHE
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.setup_fragment_cache_cache
|
19
|
-
Object.const_set(:FragmentCacheCache, Class.new { acts_as_cached :store => CACHE })
|
20
|
-
end
|
21
|
-
|
22
|
-
# add :ttl option to caches_action on the per action level by passing in a hash instead of an array
|
23
|
-
#
|
24
|
-
# Examples:
|
25
|
-
# caches_action :index # will use the default ttl from your memcache.yml, or 25 minutes
|
26
|
-
# caches_action :index => { :ttl => 5.minutes } # cache index action with 5 minute ttl
|
27
|
-
# caches_action :page, :feed, :index => { :ttl => 2.hours } # cache index action with 2 hours ttl, all others use default
|
28
|
-
#
|
29
|
-
def self.setup_rails_for_action_cache_options
|
30
|
-
::ActionController::Caching::Actions::ActionCacheFilter.class_eval do
|
31
|
-
# convert all actions into a hash keyed by action named, with a value of a ttl hash (to match other cache APIs)
|
32
|
-
def initialize(*actions, &block)
|
33
|
-
@options = actions.extract_options!
|
34
|
-
@actions = actions.inject(@options.except(:cache_path)) do |hsh, action|
|
35
|
-
action.is_a?(Hash) ? hsh.merge(action) : hsh.merge(action => { :ttl => nil })
|
36
|
-
end
|
37
|
-
@options.slice!(:cache_path)
|
38
|
-
end
|
39
|
-
|
40
|
-
# override to skip caching/rendering on evaluated if option
|
41
|
-
def before(controller)
|
42
|
-
return unless @actions.include?(controller.action_name.intern)
|
43
|
-
|
44
|
-
if @options
|
45
|
-
action_cache_path = ActionController::Caching::Actions::ActionCachePath.new(controller, path_options_for(controller, @options))
|
46
|
-
end
|
47
|
-
|
48
|
-
# should probably be like ActiveRecord::Validations.evaluate_condition. color me lazy.
|
49
|
-
if conditional = @actions[controller.action_name.intern][:if]
|
50
|
-
conditional = conditional.respond_to?(:call) ? conditional.call(controller) : controller.send(conditional)
|
51
|
-
end
|
52
|
-
@actions.delete(controller.action_name.intern) if conditional == false
|
53
|
-
|
54
|
-
cache = controller.read_fragment(action_cache_path.path)
|
55
|
-
if cache && (conditional || conditional.nil?)
|
56
|
-
controller.rendered_action_cache = true
|
57
|
-
if method(:set_content_type!).arity == 2
|
58
|
-
set_content_type!(controller, action_cache_path.extension)
|
59
|
-
else
|
60
|
-
set_content_type!(action_cache_path)
|
61
|
-
end
|
62
|
-
controller.send(:render, :text => cache)
|
63
|
-
false
|
64
|
-
else
|
65
|
-
# 1.2.x compatibility
|
66
|
-
controller.action_cache_path = action_cache_path if controller.respond_to? :action_cache_path
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
# override to pass along the ttl hash
|
71
|
-
def after(controller)
|
72
|
-
return if !@actions.include?(controller.action_name.intern) || controller.rendered_action_cache
|
73
|
-
# 1.2.x compatibility
|
74
|
-
path = controller.respond_to?(:action_cache_path) ? controller.action_cache_path.path : ActionController::Caching::Actions::ActionCachePath.path_for(controller)
|
75
|
-
controller.write_fragment(path, controller.response.body, action_ttl(controller))
|
76
|
-
end
|
77
|
-
|
78
|
-
private
|
79
|
-
def action_ttl(controller)
|
80
|
-
@actions[controller.action_name.intern]
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
module Extensions
|
86
|
-
def read(*args)
|
87
|
-
return if ActsAsCached.config[:skip_gets]
|
88
|
-
FragmentCacheCache.cache_store(:get, args.first)
|
89
|
-
end
|
90
|
-
|
91
|
-
def write(name, content, options = {})
|
92
|
-
ttl = (options.is_a?(Hash) ? options[:ttl] : nil) || ActsAsCached.config[:ttl] || 25.minutes
|
93
|
-
FragmentCacheCache.cache_store(:set, name, content, ttl)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
module DisabledExtensions
|
98
|
-
def read(*args) nil end
|
99
|
-
def write(*args) "" end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module ActsAsCached
|
2
|
-
module LocalCache
|
3
|
-
@@local_cache = {}
|
4
|
-
mattr_accessor :local_cache
|
5
|
-
|
6
|
-
def fetch_cache_with_local_cache(*args)
|
7
|
-
@@local_cache[cache_key(args.first)] ||= fetch_cache_without_local_cache(*args)
|
8
|
-
end
|
9
|
-
|
10
|
-
def set_cache_with_local_cache(*args)
|
11
|
-
@@local_cache[cache_key(args.first)] = set_cache_without_local_cache(*args)
|
12
|
-
end
|
13
|
-
|
14
|
-
def expire_cache_with_local_cache(*args)
|
15
|
-
@@local_cache.delete(cache_key(args.first))
|
16
|
-
expire_cache_without_local_cache(*args)
|
17
|
-
end
|
18
|
-
alias :clear_cache_with_local_cache :expire_cache_with_local_cache
|
19
|
-
|
20
|
-
def cached_with_local_cache?(*args)
|
21
|
-
!!@@local_cache[cache_key(args.first)] || cached_without_local_cache?(*args)
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.add_to(klass)
|
25
|
-
return if klass.ancestors.include? self
|
26
|
-
klass.send :include, self
|
27
|
-
|
28
|
-
klass.class_eval do
|
29
|
-
%w( fetch_cache set_cache expire_cache clear_cache cached? ).each do |target|
|
30
|
-
alias_method_chain target, :local_cache
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
module ActionController
|
38
|
-
class Base
|
39
|
-
def local_cache_for_request
|
40
|
-
ActsAsCached::LocalCache.add_to ActsAsCached::ClassMethods
|
41
|
-
ActsAsCached::LocalCache.local_cache = {}
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|