merb-cache 0.9.7 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +2 -2
- data/README +207 -143
- data/Rakefile +55 -10
- data/TODO +0 -2
- data/lib/merb-cache/cache.rb +84 -0
- data/lib/merb-cache/core_ext/enumerable.rb +9 -0
- data/lib/merb-cache/core_ext/hash.rb +20 -0
- data/lib/merb-cache/merb_ext/controller.rb +167 -0
- data/lib/merb-cache/stores/fundamental/abstract_store.rb +101 -0
- data/lib/merb-cache/stores/fundamental/file_store.rb +112 -0
- data/lib/merb-cache/stores/fundamental/memcached_store.rb +112 -0
- data/lib/merb-cache/stores/strategy/abstract_strategy_store.rb +123 -0
- data/lib/merb-cache/stores/strategy/action_store.rb +56 -0
- data/lib/merb-cache/stores/strategy/adhoc_store.rb +69 -0
- data/lib/merb-cache/stores/strategy/gzip_store.rb +63 -0
- data/lib/merb-cache/stores/strategy/page_store.rb +64 -0
- data/lib/merb-cache/stores/strategy/sha1_store.rb +62 -0
- data/lib/merb-cache.rb +8 -7
- data/spec/merb-cache/cache_spec.rb +88 -0
- data/spec/merb-cache/core_ext/enumerable_spec.rb +22 -0
- data/spec/merb-cache/core_ext/hash_spec.rb +20 -0
- data/spec/merb-cache/merb_ext/controller_spec.rb +284 -0
- data/spec/merb-cache/stores/fundamental/abstract_store_spec.rb +166 -0
- data/spec/merb-cache/stores/fundamental/file_store_spec.rb +186 -0
- data/spec/merb-cache/stores/fundamental/memcached_store_spec.rb +243 -0
- data/spec/merb-cache/stores/strategy/abstract_strategy_store_spec.rb +78 -0
- data/spec/merb-cache/stores/strategy/action_store_spec.rb +189 -0
- data/spec/merb-cache/stores/strategy/adhoc_store_spec.rb +225 -0
- data/spec/merb-cache/stores/strategy/gzip_store_spec.rb +51 -0
- data/spec/merb-cache/stores/strategy/page_store_spec.rb +111 -0
- data/spec/merb-cache/stores/strategy/sha1_store_spec.rb +75 -0
- data/spec/spec_helper.rb +69 -72
- metadata +42 -31
- data/lib/merb-cache/cache-action.rb +0 -144
- data/lib/merb-cache/cache-fragment.rb +0 -95
- data/lib/merb-cache/cache-page.rb +0 -203
- data/lib/merb-cache/cache-store/database-activerecord.rb +0 -88
- data/lib/merb-cache/cache-store/database-datamapper.rb +0 -79
- data/lib/merb-cache/cache-store/database-sequel.rb +0 -78
- data/lib/merb-cache/cache-store/database.rb +0 -144
- data/lib/merb-cache/cache-store/dummy.rb +0 -106
- data/lib/merb-cache/cache-store/file.rb +0 -194
- data/lib/merb-cache/cache-store/memcache.rb +0 -199
- data/lib/merb-cache/cache-store/memory.rb +0 -168
- data/lib/merb-cache/merb-cache.rb +0 -165
- data/lib/merb-cache/merbtasks.rb +0 -6
- data/spec/config/database.yml +0 -14
- data/spec/controller.rb +0 -101
- data/spec/log/merb_test.log +0 -433
- data/spec/merb-cache-action_spec.rb +0 -162
- data/spec/merb-cache-fragment_spec.rb +0 -100
- data/spec/merb-cache-page_spec.rb +0 -150
- data/spec/merb-cache_spec.rb +0 -15
- data/spec/views/cache_controller/action1.html.erb +0 -4
- data/spec/views/cache_controller/action2.html.haml +0 -4
data/spec/spec_helper.rb
CHANGED
@@ -1,84 +1,81 @@
|
|
1
|
-
|
2
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
3
|
-
require "rubygems"
|
4
|
-
require "merb-core"
|
1
|
+
$:.push File.join(File.dirname(__FILE__), '..', 'lib')
|
5
2
|
|
6
|
-
|
7
|
-
require
|
3
|
+
# Deps
|
4
|
+
require 'rubygems'
|
5
|
+
require 'merb-core'
|
6
|
+
require 'merb-action-args'
|
7
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'merb-cache')
|
8
8
|
|
9
|
-
|
9
|
+
# We want logging!
|
10
|
+
Merb.logger = Merb::Logger.new(File.join(File.dirname(__FILE__), '..', 'log', 'merb_test.log'))
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
Merb.start :environment => "test", :adapter => "runner"
|
13
|
+
|
14
|
+
require "merb-core/test"
|
15
|
+
Spec::Runner.configure do |config|
|
16
|
+
config.include Merb::Test::Helpers
|
17
|
+
#config.include Merb::Test::ControllerHelper
|
18
|
+
config.include Merb::Test::RouteHelper
|
16
19
|
end
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
Merb.logger = Merb::Logger.new("log/merb_test.log")
|
37
|
-
set_database_adapter("sqlite3")
|
38
|
-
require "merb_datamapper"
|
39
|
-
when "activerecord"
|
40
|
-
Merb.logger = Merb::Logger.new("log/merb_test.log")
|
41
|
-
set_database_adapter("sqlite3")
|
42
|
-
require "merb_activerecord"
|
43
|
-
when "sequel"
|
44
|
-
set_database_adapter("sqlite")
|
45
|
-
require "merb_sequel"
|
46
|
-
else
|
47
|
-
raise "Unknown orm: #{orm}"
|
21
|
+
class DummyStore < Merb::Cache::AbstractStore
|
22
|
+
cattr_accessor :vault
|
23
|
+
attr_accessor :options
|
24
|
+
|
25
|
+
def initialize(config = {})
|
26
|
+
super(config)
|
27
|
+
@options = config
|
28
|
+
@@vault = {}
|
29
|
+
end
|
30
|
+
|
31
|
+
def writable?(*args)
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
35
|
+
def read(key, parameters = {})
|
36
|
+
|
37
|
+
if @@vault.keys.include?(key)
|
38
|
+
@@vault[key].find {|data, timestamp, conditions, params| params == parameters}
|
48
39
|
end
|
49
|
-
else
|
50
|
-
raise "Unknown cache store: #{store}"
|
51
40
|
end
|
52
|
-
end
|
53
41
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
use_cache_store "file"
|
58
|
-
when "memory"
|
59
|
-
use_cache_store "memory"
|
60
|
-
when "memcache"
|
61
|
-
use_cache_store "memcache"
|
62
|
-
when "datamapper"
|
63
|
-
use_cache_store "database", "datamapper"
|
64
|
-
when "sequel"
|
65
|
-
use_cache_store "database", "sequel"
|
66
|
-
when "activerecord"
|
67
|
-
use_cache_store "database", "activerecord"
|
68
|
-
when "dummy"
|
69
|
-
use_cache_store "dummy"
|
70
|
-
else
|
71
|
-
puts "Invalid cache store: #{ENV["store"]}"
|
72
|
-
exit
|
73
|
-
end
|
42
|
+
def data(key, parameters = {})
|
43
|
+
read(key, parameters)[0] if read(key, parameters)
|
44
|
+
end
|
74
45
|
|
75
|
-
|
76
|
-
|
77
|
-
|
46
|
+
def time(key, parameters = {})
|
47
|
+
read(key, parameters)[1] if read(key, parameters)
|
48
|
+
end
|
78
49
|
|
79
|
-
|
50
|
+
def conditions(key, parameters = {})
|
51
|
+
read(key, parameters)[2] if read(key, parameters)
|
52
|
+
end
|
80
53
|
|
81
|
-
|
82
|
-
|
83
|
-
|
54
|
+
def write(key, data = nil, parameters = {}, conditions = {})
|
55
|
+
(@@vault[key] ||= []) << [data, Time.now, conditions, parameters]
|
56
|
+
true
|
57
|
+
end
|
58
|
+
|
59
|
+
def fetch(key, parameters = {}, conditions = {}, &blk)
|
60
|
+
@@vault[[key, parameters]] ||= blk.call
|
61
|
+
end
|
62
|
+
|
63
|
+
def exists?(key, parameters = {})
|
64
|
+
@@vault.has_key? [key, parameters]
|
65
|
+
end
|
66
|
+
|
67
|
+
def delete(key, parameters = {})
|
68
|
+
@@vault.delete([key, parameters]) unless @@vault[[key, parameters]].nil?
|
69
|
+
end
|
70
|
+
|
71
|
+
def delete_all
|
72
|
+
@@vault = {}
|
73
|
+
end
|
84
74
|
end
|
75
|
+
|
76
|
+
#TODO change this to a work queue per class called in an after aspect
|
77
|
+
class Merb::Controller
|
78
|
+
def run_later
|
79
|
+
yield
|
80
|
+
end
|
81
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merb-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Ben Burkert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-10-06 00:00:00 +03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,10 +20,10 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.9.
|
23
|
+
version: 0.9.8
|
24
24
|
version:
|
25
25
|
description: Merb plugin that provides caching (page, action, fragment, object)
|
26
|
-
email:
|
26
|
+
email: ben@benburkert.com
|
27
27
|
executables: []
|
28
28
|
|
29
29
|
extensions: []
|
@@ -38,35 +38,46 @@ files:
|
|
38
38
|
- Rakefile
|
39
39
|
- TODO
|
40
40
|
- lib/merb-cache
|
41
|
-
- lib/merb-cache/cache
|
42
|
-
- lib/merb-cache/
|
43
|
-
- lib/merb-cache/
|
44
|
-
- lib/merb-cache/
|
45
|
-
- lib/merb-cache/
|
46
|
-
- lib/merb-cache/
|
47
|
-
- lib/merb-cache/
|
48
|
-
- lib/merb-cache/
|
49
|
-
- lib/merb-cache/
|
50
|
-
- lib/merb-cache/
|
51
|
-
- lib/merb-cache/
|
52
|
-
- lib/merb-cache/
|
53
|
-
- lib/merb-cache/
|
54
|
-
- lib/merb-cache/
|
41
|
+
- lib/merb-cache/cache.rb
|
42
|
+
- lib/merb-cache/core_ext
|
43
|
+
- lib/merb-cache/core_ext/enumerable.rb
|
44
|
+
- lib/merb-cache/core_ext/hash.rb
|
45
|
+
- lib/merb-cache/merb_ext
|
46
|
+
- lib/merb-cache/merb_ext/controller.rb
|
47
|
+
- lib/merb-cache/stores
|
48
|
+
- lib/merb-cache/stores/fundamental
|
49
|
+
- lib/merb-cache/stores/fundamental/abstract_store.rb
|
50
|
+
- lib/merb-cache/stores/fundamental/file_store.rb
|
51
|
+
- lib/merb-cache/stores/fundamental/memcached_store.rb
|
52
|
+
- lib/merb-cache/stores/strategy
|
53
|
+
- lib/merb-cache/stores/strategy/abstract_strategy_store.rb
|
54
|
+
- lib/merb-cache/stores/strategy/action_store.rb
|
55
|
+
- lib/merb-cache/stores/strategy/adhoc_store.rb
|
56
|
+
- lib/merb-cache/stores/strategy/gzip_store.rb
|
57
|
+
- lib/merb-cache/stores/strategy/page_store.rb
|
58
|
+
- lib/merb-cache/stores/strategy/sha1_store.rb
|
55
59
|
- lib/merb-cache.rb
|
56
|
-
- spec/config
|
57
|
-
- spec/config/database.yml
|
58
|
-
- spec/controller.rb
|
59
60
|
- spec/log
|
60
|
-
- spec/
|
61
|
-
- spec/merb-cache
|
62
|
-
- spec/merb-cache
|
63
|
-
- spec/merb-cache
|
64
|
-
- spec/merb-
|
61
|
+
- spec/merb-cache
|
62
|
+
- spec/merb-cache/cache_spec.rb
|
63
|
+
- spec/merb-cache/core_ext
|
64
|
+
- spec/merb-cache/core_ext/enumerable_spec.rb
|
65
|
+
- spec/merb-cache/core_ext/hash_spec.rb
|
66
|
+
- spec/merb-cache/merb_ext
|
67
|
+
- spec/merb-cache/merb_ext/controller_spec.rb
|
68
|
+
- spec/merb-cache/stores
|
69
|
+
- spec/merb-cache/stores/fundamental
|
70
|
+
- spec/merb-cache/stores/fundamental/abstract_store_spec.rb
|
71
|
+
- spec/merb-cache/stores/fundamental/file_store_spec.rb
|
72
|
+
- spec/merb-cache/stores/fundamental/memcached_store_spec.rb
|
73
|
+
- spec/merb-cache/stores/strategy
|
74
|
+
- spec/merb-cache/stores/strategy/abstract_strategy_store_spec.rb
|
75
|
+
- spec/merb-cache/stores/strategy/action_store_spec.rb
|
76
|
+
- spec/merb-cache/stores/strategy/adhoc_store_spec.rb
|
77
|
+
- spec/merb-cache/stores/strategy/gzip_store_spec.rb
|
78
|
+
- spec/merb-cache/stores/strategy/page_store_spec.rb
|
79
|
+
- spec/merb-cache/stores/strategy/sha1_store_spec.rb
|
65
80
|
- spec/spec_helper.rb
|
66
|
-
- spec/views
|
67
|
-
- spec/views/cache_controller
|
68
|
-
- spec/views/cache_controller/action1.html.erb
|
69
|
-
- spec/views/cache_controller/action2.html.haml
|
70
81
|
has_rdoc: true
|
71
82
|
homepage: http://merbivore.com
|
72
83
|
post_install_message:
|
@@ -1,144 +0,0 @@
|
|
1
|
-
class Merb::Cache
|
2
|
-
cattr_accessor :cached_actions
|
3
|
-
self.cached_actions = {}
|
4
|
-
end
|
5
|
-
|
6
|
-
module Merb::Cache::ControllerClassMethods
|
7
|
-
# Mixed in Merb::Controller. Provides methods related to action caching.
|
8
|
-
|
9
|
-
# Registers an action for action caching via before and after filters.
|
10
|
-
#
|
11
|
-
# ==== Parameters
|
12
|
-
# action<Symbol>:: The name of the action to register.
|
13
|
-
# from_now<~minutes>:: The number of minutes (from now) the cache should persist.
|
14
|
-
# opts<Hash>::
|
15
|
-
# Filter options (see <tt>Filter Options</tt> in <tt>Merb::AbstractController</tt>). The filters created apply :only
|
16
|
-
# to specified <tt>action</tt>.
|
17
|
-
#
|
18
|
-
# ==== Examples
|
19
|
-
# cache_action :mostly_static
|
20
|
-
# cache_action :barely_dynamic, 10
|
21
|
-
# cache_action :list, :if => Proc.new { |controller| !controller.params[:id].empty? }
|
22
|
-
# cache_action :show, :unless => proc { |controller| !controller.params[:id].empty? }
|
23
|
-
def cache_action(action, from_now = nil, opts = {})
|
24
|
-
cache_actions([action, from_now, opts])
|
25
|
-
end
|
26
|
-
|
27
|
-
# Register multiple actions for action caching via before and after filters.
|
28
|
-
#
|
29
|
-
# ==== Parameter
|
30
|
-
# actions<Symbol,Array[Symbol,~minutes],Hash>:: See #cache_action.
|
31
|
-
#
|
32
|
-
# ==== Example
|
33
|
-
# cache_actions(
|
34
|
-
# :mostly_static,
|
35
|
-
# [:barely_dynamic, 10],
|
36
|
-
# [:conditional, { :if => proc { |controller| controller.params[:id].empty? } }]
|
37
|
-
# )
|
38
|
-
def cache_actions(*actions)
|
39
|
-
actions.each do |action, from_now, opts|
|
40
|
-
from_now, opts = nil, from_now if Hash === from_now
|
41
|
-
opts ||= {}
|
42
|
-
|
43
|
-
before("cache_#{action}_before", opts.merge(:only => action))
|
44
|
-
after("cache_#{action}_after", opts.merge(:only => action))
|
45
|
-
alias_method "cache_#{action}_before", :cache_action_before
|
46
|
-
alias_method "cache_#{action}_after", :cache_action_after
|
47
|
-
|
48
|
-
_actions = Merb::Cache.cached_actions[controller_name] ||= {}
|
49
|
-
_actions[action] = from_now
|
50
|
-
end
|
51
|
-
true
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
module Merb::Cache::ControllerInstanceMethods
|
56
|
-
# Mixed in Merb::Controller. Provides methods related to action caching
|
57
|
-
|
58
|
-
# Checks whether a cache entry exists
|
59
|
-
#
|
60
|
-
# ==== Parameter
|
61
|
-
# options<String,Hash>:: The options that will be passed to #key_for
|
62
|
-
#
|
63
|
-
# ==== Returns
|
64
|
-
# true if the cache entry exists, false otherwise
|
65
|
-
#
|
66
|
-
# ==== Example
|
67
|
-
# cached_action?(:action => 'show', :params => [params[:page]])
|
68
|
-
def cached_action?(options)
|
69
|
-
key = Merb::Controller._cache.key_for(options, controller_name, true)
|
70
|
-
Merb::Controller._cache.store.cached?(key)
|
71
|
-
end
|
72
|
-
|
73
|
-
# Expires the action identified by the key computed after the parameters
|
74
|
-
#
|
75
|
-
# ==== Parameter
|
76
|
-
# options<String,Hash>:: The options that will be passed to #expire_key_for
|
77
|
-
#
|
78
|
-
# ==== Examples
|
79
|
-
# expire_action(:action => 'show', :controller => 'news')
|
80
|
-
# expire_action(:action => 'show', :match => true)
|
81
|
-
def expire_action(options)
|
82
|
-
Merb::Controller._cache.expire_key_for(options, controller_name, true) do |key, match|
|
83
|
-
if match
|
84
|
-
Merb::Controller._cache.store.expire_match(key)
|
85
|
-
else
|
86
|
-
Merb::Controller._cache.store.expire(key)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
true
|
90
|
-
end
|
91
|
-
|
92
|
-
# You can call this method if you need to prevent caching the action
|
93
|
-
# after it has been rendered.
|
94
|
-
def abort_cache_action
|
95
|
-
@capture_action = false
|
96
|
-
end
|
97
|
-
|
98
|
-
private
|
99
|
-
|
100
|
-
# Called by the before and after filters. Stores or recalls a cache entry.
|
101
|
-
# The key is based on the result of request.path
|
102
|
-
# If the key with "/" then it is removed
|
103
|
-
# If the key is "/" then it will be replaced by "index"
|
104
|
-
#
|
105
|
-
# ==== Parameters
|
106
|
-
# data<String>:: the data to put in cache using the cache store
|
107
|
-
#
|
108
|
-
# ==== Examples
|
109
|
-
# If request.path is "/", the key will be "index"
|
110
|
-
# If request.path is "/news/show/1", the key will be "/news/show/1"
|
111
|
-
# If request.path is "/news/show/", the key will be "/news/show"
|
112
|
-
def _cache_action(data = nil)
|
113
|
-
controller = controller_name
|
114
|
-
action = action_name.to_sym
|
115
|
-
actions = Merb::Controller._cache.cached_actions[controller]
|
116
|
-
return unless actions && actions.key?(action)
|
117
|
-
path = request.path.chomp("/")
|
118
|
-
path = "index" if path.empty?
|
119
|
-
if data
|
120
|
-
from_now = Merb::Controller._cache.cached_actions[controller][action]
|
121
|
-
Merb::Controller._cache.store.cache_set(path, data, from_now)
|
122
|
-
else
|
123
|
-
@capture_action = false
|
124
|
-
_data = Merb::Controller._cache.store.cache_get(path)
|
125
|
-
throw(:halt, _data) unless _data.nil?
|
126
|
-
@capture_action = true
|
127
|
-
end
|
128
|
-
true
|
129
|
-
end
|
130
|
-
|
131
|
-
# before filter
|
132
|
-
def cache_action_before
|
133
|
-
# recalls a cached entry or set @capture_action to true in order
|
134
|
-
# to grab the response in the after filter
|
135
|
-
_cache_action
|
136
|
-
end
|
137
|
-
|
138
|
-
# after filter
|
139
|
-
def cache_action_after
|
140
|
-
# takes the body of the response and put it in cache
|
141
|
-
# if the cache entry expired, if it doesn't exist or status is 200
|
142
|
-
_cache_action(body) if @capture_action && status == 200
|
143
|
-
end
|
144
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
module Merb::Cache::ControllerInstanceMethods
|
2
|
-
# Mixed in Merb::Controller. Provides methods related to fragment caching
|
3
|
-
|
4
|
-
# Checks whether a cache entry exists
|
5
|
-
#
|
6
|
-
# ==== Parameter
|
7
|
-
# options<String,Hash>:: The options that will be passed to #key_for
|
8
|
-
#
|
9
|
-
# ==== Returns
|
10
|
-
# true if the cache entry exists, false otherwise
|
11
|
-
#
|
12
|
-
# ==== Example
|
13
|
-
# cached_action?("my_key")
|
14
|
-
def cached?(options)
|
15
|
-
key = Merb::Controller._cache.key_for(options, controller_name)
|
16
|
-
Merb::Controller._cache.store.cached?(key)
|
17
|
-
end
|
18
|
-
|
19
|
-
# ==== Example
|
20
|
-
# In your view:
|
21
|
-
# <%- cache("my_key") do -%>
|
22
|
-
# <%= partial :test, :collection => @test %>
|
23
|
-
# <%- end -%>
|
24
|
-
def cache(options, from_now = nil, &block)
|
25
|
-
key = Merb::Controller._cache.key_for(options, controller_name)
|
26
|
-
Merb::Controller._cache.store.cache(self, key, from_now, &block)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Fetch data from cache
|
30
|
-
#
|
31
|
-
# ==== Parameter
|
32
|
-
# options<String,Hash>:: The options that will be passed to #key_for
|
33
|
-
#
|
34
|
-
# ==== Returns
|
35
|
-
# data<Object,NilClass>::
|
36
|
-
# nil is returned if the cache entry is not found
|
37
|
-
#
|
38
|
-
# ==== Example
|
39
|
-
# if cache_data = cache_get("my_key")
|
40
|
-
# @var1, @var2 = *cache_data
|
41
|
-
# else
|
42
|
-
# @var1 = MyModel.big_query1
|
43
|
-
# @var2 = MyModel.big_query2
|
44
|
-
# cache_set("my_key", nil, [@var1, @var2])
|
45
|
-
# end
|
46
|
-
def cache_get(options)
|
47
|
-
key = Merb::Controller._cache.key_for(options, controller_name)
|
48
|
-
Merb::Controller._cache.store.cache_get(key)
|
49
|
-
end
|
50
|
-
|
51
|
-
# Store data to cache
|
52
|
-
#
|
53
|
-
# ==== Parameter
|
54
|
-
# options<String,Hash>:: The options that will be passed to #key_for
|
55
|
-
# object<Object>:: The object(s) to put in cache
|
56
|
-
# from_now<~minutes>::
|
57
|
-
# The number of minutes (from now) the cache should persist
|
58
|
-
#
|
59
|
-
# ==== Returns
|
60
|
-
# data<Object,NilClass>::
|
61
|
-
# nil is returned if the cache entry is not found
|
62
|
-
#
|
63
|
-
# ==== Example
|
64
|
-
# if cache_data = cache_get("my_key")
|
65
|
-
# @var1, @var2 = *cache_data
|
66
|
-
# else
|
67
|
-
# @var1 = MyModel.big_query1
|
68
|
-
# @var2 = MyModel.big_query2
|
69
|
-
# cache_set("my_key", nil, [@var1, @var2])
|
70
|
-
# end
|
71
|
-
def cache_set(options, object, from_now = nil)
|
72
|
-
key = Merb::Controller._cache.key_for(options, controller_name)
|
73
|
-
Merb::Controller._cache.store.cache_set(key, object, from_now)
|
74
|
-
end
|
75
|
-
|
76
|
-
# Expires the entry identified by the key computed after the parameters
|
77
|
-
#
|
78
|
-
# ==== Parameter
|
79
|
-
# options<String,Hash>:: The options that will be passed to #key_for
|
80
|
-
#
|
81
|
-
# ==== Examples
|
82
|
-
# expire("my_key")
|
83
|
-
# expire(:key => "my_", :match => true)
|
84
|
-
# expire(:key => "my_key", :params => [session[:me], params[:ref]])
|
85
|
-
def expire(options)
|
86
|
-
Merb::Controller._cache.expire_key_for(options, controller_name) do |key, match|
|
87
|
-
if match
|
88
|
-
Merb::Controller._cache.store.expire_match(key)
|
89
|
-
else
|
90
|
-
Merb::Controller._cache.store.expire(key)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
true
|
94
|
-
end
|
95
|
-
end
|