padrino-cache 0.16.0.pre4 → 0.16.0
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.
- checksums.yaml +4 -4
- data/README.rdoc +30 -30
- data/Rakefile +1 -1
- data/lib/padrino-cache/helpers/cache_object.rb +2 -2
- data/lib/padrino-cache/helpers/cache_store.rb +1 -1
- data/lib/padrino-cache/helpers/fragment.rb +5 -5
- data/lib/padrino-cache/helpers/page.rb +13 -13
- data/lib/padrino-cache.rb +16 -16
- data/padrino-cache.gemspec +17 -17
- data/test/helper.rb +2 -2
- data/test/test_moneta_store.rb +9 -9
- data/test/test_padrino_cache.rb +99 -101
- metadata +8 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 44e68b83c64abb2de33377f04f6e70de52b80ddcabe240f25659787e33a5521d
|
|
4
|
+
data.tar.gz: a5914bb48bc0d0a7bf010330405b4070c588756e1b7974c0eb63489b8b8ed228
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c242ed3f212630753edfce0f21bd48873524194971763cf63a31b3de785397e40ed3fe5625318a049d64ec97a5c785927841a75ea768eda29c94519f255adc37
|
|
7
|
+
data.tar.gz: 62b5cd8edfac34eb057df321641179d2d752c8c37ecbb311d40f6ae4f836d90140e5022897690d54852479f0debd912e587c94fa78627ea95c30732e19109c53
|
data/README.rdoc
CHANGED
|
@@ -26,7 +26,7 @@ your needs, you can enable it very easily:
|
|
|
26
26
|
register Padrino::Cache
|
|
27
27
|
enable :caching
|
|
28
28
|
|
|
29
|
-
get '/foo', :
|
|
29
|
+
get '/foo', cache: true do
|
|
30
30
|
expires 30 # expire cached version at least every 30 seconds
|
|
31
31
|
'Hello world'
|
|
32
32
|
end
|
|
@@ -44,7 +44,7 @@ You can also cache on a controller-wide basis:
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
# Requests to routes within '/admin'
|
|
47
|
-
controller '/admin', :
|
|
47
|
+
controller '/admin', cache: true do
|
|
48
48
|
expires 60
|
|
49
49
|
|
|
50
50
|
get '/foo' do
|
|
@@ -67,7 +67,7 @@ You can also provide a custom <tt>cache_key</tt> in any route:
|
|
|
67
67
|
register Padrino::Cache
|
|
68
68
|
enable :caching
|
|
69
69
|
|
|
70
|
-
get '/post/:id', :
|
|
70
|
+
get '/post/:id', cache: true do
|
|
71
71
|
@post = Post.find(params[:id])
|
|
72
72
|
cache_key :my_name
|
|
73
73
|
end
|
|
@@ -76,7 +76,7 @@ You can also provide a custom <tt>cache_key</tt> in any route:
|
|
|
76
76
|
In this way you can manually expire cache with CachedApp.cache.delete(:my_name)
|
|
77
77
|
for example from the Post model after an update.
|
|
78
78
|
|
|
79
|
-
If you specify <tt
|
|
79
|
+
If you specify <tt>cache: true</tt> but do not invoke <tt>expires</tt>,
|
|
80
80
|
the response will be cached indefinitely. Most of the time, you will want to
|
|
81
81
|
specify the expiry of a cache entry by <tt>expires</tt>. Even a relatively
|
|
82
82
|
low value--1 or 2 seconds--can greatly increase application efficiency, especially
|
|
@@ -107,7 +107,7 @@ The padrino-cache helpers are made available to your application thusly:
|
|
|
107
107
|
|
|
108
108
|
As described above in the "Caching Quickstart" section, page caching is very
|
|
109
109
|
easy to integrate into your application. To turn it on, simply provide the
|
|
110
|
-
<tt
|
|
110
|
+
<tt>cache: true</tt> option on either a controller or one of its routes.
|
|
111
111
|
By default, cached content is persisted with a "file store"--that is, in a
|
|
112
112
|
subdirectory of your application root.
|
|
113
113
|
|
|
@@ -126,7 +126,7 @@ be executed; rather, its previous output will be sent to the client with a
|
|
|
126
126
|
register Padrino::Cache # includes helpers
|
|
127
127
|
enable :caching # turns on caching
|
|
128
128
|
|
|
129
|
-
controller '/blog', :
|
|
129
|
+
controller '/blog', cache: true do
|
|
130
130
|
expires 15
|
|
131
131
|
|
|
132
132
|
get '/entries' do
|
|
@@ -163,11 +163,11 @@ to be cached. It can be used in within a route:
|
|
|
163
163
|
enable :caching # turns on caching
|
|
164
164
|
|
|
165
165
|
controller '/tweets' do
|
|
166
|
-
get :feed, :
|
|
166
|
+
get :feed, map: '/:username' do
|
|
167
167
|
username = params[:username]
|
|
168
168
|
|
|
169
|
-
@feed = cache(
|
|
170
|
-
@tweets = Tweet.all(
|
|
169
|
+
@feed = cache("feed_for_#{username}", expires: 3) do
|
|
170
|
+
@tweets = Tweet.all(username: username)
|
|
171
171
|
render 'partials/feedcontent'
|
|
172
172
|
end
|
|
173
173
|
|
|
@@ -190,11 +190,11 @@ Note that any other action will reference the same content if it uses the same k
|
|
|
190
190
|
enable :caching # turns on caching
|
|
191
191
|
|
|
192
192
|
controller :tweets do
|
|
193
|
-
get :feed, :
|
|
193
|
+
get :feed, map: '/:username' do
|
|
194
194
|
username = params[:username]
|
|
195
195
|
|
|
196
|
-
@feed = cache(
|
|
197
|
-
@tweets = Tweet.all(
|
|
196
|
+
@feed = cache("feed_for_#{username}", expires: 3) do
|
|
197
|
+
@tweets = Tweet.all(username: username)
|
|
198
198
|
render 'partials/feedcontent'
|
|
199
199
|
end
|
|
200
200
|
|
|
@@ -202,11 +202,11 @@ Note that any other action will reference the same content if it uses the same k
|
|
|
202
202
|
render 'feeds/show'
|
|
203
203
|
end
|
|
204
204
|
|
|
205
|
-
get :mobile_feed, :
|
|
205
|
+
get :mobile_feed, map: '/:username.iphone' do
|
|
206
206
|
username = params[:username]
|
|
207
207
|
|
|
208
|
-
@feed = cache(
|
|
209
|
-
@tweets = Tweet.all(
|
|
208
|
+
@feed = cache("feed_for_#{username}", expires: 3) do
|
|
209
|
+
@tweets = Tweet.all(username: username)
|
|
210
210
|
render 'partials/feedcontent'
|
|
211
211
|
end
|
|
212
212
|
|
|
@@ -228,17 +228,17 @@ Finally, to DRY up things a bit, we might do:
|
|
|
228
228
|
controller :tweets do
|
|
229
229
|
# This works because all routes in this controller specify :username
|
|
230
230
|
before do
|
|
231
|
-
@feed = cache(
|
|
232
|
-
@tweets = Tweet.all(
|
|
231
|
+
@feed = cache("feed_for_#{params[:username]}", expires: 3) do
|
|
232
|
+
@tweets = Tweet.all(username: params[:username])
|
|
233
233
|
render 'partials/feedcontent'
|
|
234
234
|
end
|
|
235
235
|
end
|
|
236
236
|
|
|
237
|
-
get :feed, :
|
|
237
|
+
get :feed, map: '/:username' do
|
|
238
238
|
render 'feeds/show'
|
|
239
239
|
end
|
|
240
240
|
|
|
241
|
-
get :mobile_feed, :
|
|
241
|
+
get :mobile_feed, map: '/:username.iphone' do
|
|
242
242
|
render 'feeds/show.iphone'
|
|
243
243
|
end
|
|
244
244
|
end
|
|
@@ -256,15 +256,15 @@ You can set a global caching option or a per app caching options.
|
|
|
256
256
|
=== Global Caching Options
|
|
257
257
|
|
|
258
258
|
Padrino.cache = Padrino::Cache.new(:LRUHash) # default choice
|
|
259
|
-
Padrino.cache = Padrino::Cache.new(:File, :
|
|
259
|
+
Padrino.cache = Padrino::Cache.new(:File, dir: Padrino.root('tmp', app_name.to_s, 'cache')) # Keeps cached values in file
|
|
260
260
|
Padrino.cache = Padrino::Cache.new(:Memcached) # Uses default server at localhost
|
|
261
|
-
Padrino.cache = Padrino::Cache.new(:Memcached, :
|
|
262
|
-
Padrino.cache = Padrino::Cache.new(:Memcached, :
|
|
261
|
+
Padrino.cache = Padrino::Cache.new(:Memcached, server: '127.0.0.1:11211', exception_retry_limit: 1)
|
|
262
|
+
Padrino.cache = Padrino::Cache.new(:Memcached, backend: memcached_or_dalli_instance)
|
|
263
263
|
Padrino.cache = Padrino::Cache.new(:Redis) # Uses default server at localhost
|
|
264
|
-
Padrino.cache = Padrino::Cache.new(:Redis, :
|
|
265
|
-
Padrino.cache = Padrino::Cache.new(:Redis, :
|
|
264
|
+
Padrino.cache = Padrino::Cache.new(:Redis, host: '127.0.0.1', port: 6379, db: 0)
|
|
265
|
+
Padrino.cache = Padrino::Cache.new(:Redis, backend: redis_instance)
|
|
266
266
|
Padrino.cache = Padrino::Cache.new(:Mongo) # Uses default server at localhost
|
|
267
|
-
Padrino.cache = Padrino::Cache.new(:Mongo, :
|
|
267
|
+
Padrino.cache = Padrino::Cache.new(:Mongo, backend: mongo_client_instance)
|
|
268
268
|
|
|
269
269
|
You can manage your cache from anywhere in your app:
|
|
270
270
|
|
|
@@ -281,7 +281,7 @@ have special requirements, for example if you want to configure the marshalling
|
|
|
281
281
|
set :cache, Padrino::Cache.new(:LRUHash)
|
|
282
282
|
set :cache, Padrino::Cache.new(:Memcached)
|
|
283
283
|
set :cache, Padrino::Cache.new(:Redis)
|
|
284
|
-
set :cache, Padrino::Cache.new(:File, :
|
|
284
|
+
set :cache, Padrino::Cache.new(:File, dir: Padrino.root('tmp', app_name.to_s, 'cache')) # default choice
|
|
285
285
|
|
|
286
286
|
You can manage your cache from anywhere in your app:
|
|
287
287
|
|
|
@@ -314,16 +314,16 @@ do our user a favor and instantly re-render the feed.
|
|
|
314
314
|
COMPANY_FOUNDING = Time.utc( 2010, "April" )
|
|
315
315
|
|
|
316
316
|
controller :tweets do
|
|
317
|
-
get :feed, :
|
|
317
|
+
get :feed, map: '/:username' do
|
|
318
318
|
last_visit = session[:last_visit] || params[:since] || COMPANY_FOUNDING
|
|
319
319
|
|
|
320
320
|
username = params[:username]
|
|
321
|
-
@tweets = Tweet.since(
|
|
321
|
+
@tweets = Tweet.since(last_visit, username: username).limit(100)
|
|
322
322
|
|
|
323
|
-
expire(
|
|
323
|
+
expire("feed since #{last_visit}") if @tweets.any? { |t| t.deleted_since?(last_visit) }
|
|
324
324
|
|
|
325
325
|
session[:last_visit] = Time.now
|
|
326
|
-
@feed = cache(
|
|
326
|
+
@feed = cache("feed since #{last_visit}", expires: 60) do
|
|
327
327
|
@tweets = @tweets.find_all { |t| !t.deleted? }
|
|
328
328
|
render 'partials/feedcontent'
|
|
329
329
|
end
|
data/Rakefile
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative '../gem_rake_helper'
|
|
@@ -7,11 +7,11 @@ module Padrino
|
|
|
7
7
|
began_at = Time.now
|
|
8
8
|
if settings.cache.key?(key.to_s)
|
|
9
9
|
value = settings.cache[key.to_s]
|
|
10
|
-
logger.debug
|
|
10
|
+
logger.debug 'GET Object', began_at, key.to_s if defined?(logger)
|
|
11
11
|
else
|
|
12
12
|
value = yield
|
|
13
13
|
settings.cache.store(key.to_s, value, opts)
|
|
14
|
-
logger.debug
|
|
14
|
+
logger.debug 'SET Object', began_at, key.to_s if defined?(logger)
|
|
15
15
|
end
|
|
16
16
|
value
|
|
17
17
|
else
|
|
@@ -3,7 +3,7 @@ module Padrino
|
|
|
3
3
|
module Helpers
|
|
4
4
|
module CacheStore
|
|
5
5
|
def expire(*key)
|
|
6
|
-
if key.size == 1
|
|
6
|
+
if (key.size == 1) && (key.first.is_a?(String) || key.first.is_a?(Symbol))
|
|
7
7
|
settings.cache.delete(key.first)
|
|
8
8
|
else
|
|
9
9
|
settings.cache.delete(self.class.url(*key))
|
|
@@ -33,11 +33,11 @@ module Padrino
|
|
|
33
33
|
# enable :caching # turns on caching mechanism
|
|
34
34
|
#
|
|
35
35
|
# controller '/tweets' do
|
|
36
|
-
# get :feed, :
|
|
36
|
+
# get :feed, map: '/:username' do
|
|
37
37
|
# username = params[:username]
|
|
38
38
|
#
|
|
39
|
-
# @feed = cache(
|
|
40
|
-
# @tweets = Tweet.all(
|
|
39
|
+
# @feed = cache("feed_for_#{username}", expires: 3) do
|
|
40
|
+
# @tweets = Tweet.all(username: username)
|
|
41
41
|
# render 'partials/feedcontent'
|
|
42
42
|
# end
|
|
43
43
|
#
|
|
@@ -53,12 +53,12 @@ module Padrino
|
|
|
53
53
|
began_at = Time.now
|
|
54
54
|
if settings.cache.key?(key.to_s)
|
|
55
55
|
value = settings.cache[key.to_s]
|
|
56
|
-
logger.debug
|
|
56
|
+
logger.debug 'GET Fragment', began_at, key.to_s if defined?(logger)
|
|
57
57
|
concat_content(value.to_s.html_safe)
|
|
58
58
|
else
|
|
59
59
|
value = capture_html(&block)
|
|
60
60
|
settings.cache.store(key.to_s, value, opts)
|
|
61
|
-
logger.debug
|
|
61
|
+
logger.debug 'SET Fragment', began_at, key.to_s if defined?(logger)
|
|
62
62
|
concat_content(value)
|
|
63
63
|
end
|
|
64
64
|
else
|
|
@@ -6,7 +6,7 @@ module Padrino
|
|
|
6
6
|
module Helpers
|
|
7
7
|
##
|
|
8
8
|
# Page caching is easy to integrate into your application. To turn it on, simply provide the
|
|
9
|
-
# <tt
|
|
9
|
+
# <tt>cache: true</tt> option on either a controller or one of its routes.
|
|
10
10
|
# By default, cached content is persisted with a "file store" --that is, in a
|
|
11
11
|
# subdirectory of your application root.
|
|
12
12
|
#
|
|
@@ -15,7 +15,7 @@ module Padrino
|
|
|
15
15
|
# class CachedApp < Padrino::Application
|
|
16
16
|
# enable :caching # turns on caching mechanism
|
|
17
17
|
#
|
|
18
|
-
# controller '/blog', :
|
|
18
|
+
# controller '/blog', cache: true do
|
|
19
19
|
# expires 15
|
|
20
20
|
#
|
|
21
21
|
# get '/entries' do
|
|
@@ -50,7 +50,7 @@ module Padrino
|
|
|
50
50
|
# Time til expiration (seconds)
|
|
51
51
|
#
|
|
52
52
|
# @example
|
|
53
|
-
# controller '/blog', :
|
|
53
|
+
# controller '/blog', cache: true do
|
|
54
54
|
# expires 15
|
|
55
55
|
#
|
|
56
56
|
# get '/entries' do
|
|
@@ -72,7 +72,7 @@ module Padrino
|
|
|
72
72
|
# block to be evaluated to cache key
|
|
73
73
|
#
|
|
74
74
|
# @example
|
|
75
|
-
# controller '/blog', :
|
|
75
|
+
# controller '/blog', cache: true do
|
|
76
76
|
#
|
|
77
77
|
# get '/post/:id' do
|
|
78
78
|
# cache_key :my_name
|
|
@@ -81,14 +81,14 @@ module Padrino
|
|
|
81
81
|
# end
|
|
82
82
|
#
|
|
83
83
|
# @example
|
|
84
|
-
# get '/foo', :
|
|
84
|
+
# get '/foo', cache: true do
|
|
85
85
|
# cache_key { param[:id] }
|
|
86
86
|
# "My id is #{param[:id}"
|
|
87
87
|
# end
|
|
88
88
|
# end
|
|
89
89
|
#
|
|
90
90
|
def cache_key(name = nil, &block)
|
|
91
|
-
|
|
91
|
+
raise 'Can not provide both cache_key and a block' if name && block
|
|
92
92
|
@route.cache_key = name || block
|
|
93
93
|
end
|
|
94
94
|
|
|
@@ -99,7 +99,7 @@ module Padrino
|
|
|
99
99
|
|
|
100
100
|
route.before_filters do
|
|
101
101
|
next unless settings.caching?
|
|
102
|
-
if cached_response = load_cached_response
|
|
102
|
+
if (cached_response = load_cached_response)
|
|
103
103
|
content_type cached_response[:content_type]
|
|
104
104
|
halt 200, cached_response[:body]
|
|
105
105
|
end
|
|
@@ -117,25 +117,25 @@ module Padrino
|
|
|
117
117
|
route_cache_key = resolve_cache_key || env['PATH_INFO']
|
|
118
118
|
|
|
119
119
|
value = settings.cache[route_cache_key]
|
|
120
|
-
logger.debug
|
|
120
|
+
logger.debug 'GET Cache', began_at, route_cache_key if defined?(logger) && value
|
|
121
121
|
|
|
122
122
|
value
|
|
123
123
|
end
|
|
124
124
|
|
|
125
125
|
def save_cached_response(cache_expires)
|
|
126
|
-
return unless @_response_buffer.
|
|
126
|
+
return unless @_response_buffer.is_a?(String)
|
|
127
127
|
|
|
128
128
|
began_at = Time.now
|
|
129
129
|
route_cache_key = resolve_cache_key || env['PATH_INFO']
|
|
130
130
|
|
|
131
131
|
content = {
|
|
132
|
-
:
|
|
133
|
-
:
|
|
132
|
+
body: @_response_buffer,
|
|
133
|
+
content_type: response.content_type
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
settings.cache.store(route_cache_key, content, :
|
|
136
|
+
settings.cache.store(route_cache_key, content, expires: cache_expires)
|
|
137
137
|
|
|
138
|
-
logger.debug
|
|
138
|
+
logger.debug 'SET Cache', began_at, route_cache_key if defined?(logger)
|
|
139
139
|
end
|
|
140
140
|
|
|
141
141
|
##
|
data/lib/padrino-cache.rb
CHANGED
|
@@ -10,7 +10,7 @@ module Padrino
|
|
|
10
10
|
# Returns the caching engine.
|
|
11
11
|
#
|
|
12
12
|
# @example
|
|
13
|
-
# # with: Padrino.cache = Padrino::Cache.new(:File, :
|
|
13
|
+
# # with: Padrino.cache = Padrino::Cache.new(:File, dir: /my/cache/path)
|
|
14
14
|
# Padrino.cache['val'] = 'test'
|
|
15
15
|
# Padrino.cache['val'] # => 'test'
|
|
16
16
|
# Padrino.cache.delete('val')
|
|
@@ -28,15 +28,15 @@ module Padrino
|
|
|
28
28
|
#
|
|
29
29
|
# @example
|
|
30
30
|
# Padrino.cache = Padrino::Cache.new(:LRUHash) # default choice
|
|
31
|
-
# Padrino.cache = Padrino::Cache.new(:File, :
|
|
31
|
+
# Padrino.cache = Padrino::Cache.new(:File, dir: Padrino.root('tmp', app_name.to_s, 'cache')) # Keeps cached values in file
|
|
32
32
|
# Padrino.cache = Padrino::Cache.new(:Memcached) # Uses default server at localhost
|
|
33
|
-
# Padrino.cache = Padrino::Cache.new(:Memcached, :
|
|
34
|
-
# Padrino.cache = Padrino::Cache.new(:Memcached, :
|
|
33
|
+
# Padrino.cache = Padrino::Cache.new(:Memcached, server: '127.0.0.1:11211', exception_retry_limit: 1)
|
|
34
|
+
# Padrino.cache = Padrino::Cache.new(:Memcached, backend: memcached_or_dalli_instance)
|
|
35
35
|
# Padrino.cache = Padrino::Cache.new(:Redis) # Uses default server at localhost
|
|
36
|
-
# Padrino.cache = Padrino::Cache.new(:Redis, :
|
|
37
|
-
# Padrino.cache = Padrino::Cache.new(:Redis, :
|
|
36
|
+
# Padrino.cache = Padrino::Cache.new(:Redis, host: '127.0.0.1', port: 6379, db: 0)
|
|
37
|
+
# Padrino.cache = Padrino::Cache.new(:Redis, backend: redis_instance)
|
|
38
38
|
# Padrino.cache = Padrino::Cache.new(:Mongo) # Uses default server at localhost
|
|
39
|
-
# Padrino.cache = Padrino::Cache.new(:Mongo, :
|
|
39
|
+
# Padrino.cache = Padrino::Cache.new(:Mongo, backend: mongo_client_instance)
|
|
40
40
|
#
|
|
41
41
|
# # You can manage your cache from anywhere in your app:
|
|
42
42
|
#
|
|
@@ -46,7 +46,7 @@ module Padrino
|
|
|
46
46
|
# Padrino.cache.clear
|
|
47
47
|
#
|
|
48
48
|
def cache=(value)
|
|
49
|
-
@_cache= value
|
|
49
|
+
@_cache = value
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
@@ -70,20 +70,20 @@ module Padrino
|
|
|
70
70
|
#
|
|
71
71
|
# By default we use FileStore as showed below:
|
|
72
72
|
#
|
|
73
|
-
# set :cache, Padrino::Cache.new(:File, :
|
|
73
|
+
# set :cache, Padrino::Cache.new(:File, dir: Padrino.root('tmp', app_name.to_s, 'cache'))
|
|
74
74
|
#
|
|
75
75
|
# However, you can also change the file store easily in your app.rb:
|
|
76
76
|
#
|
|
77
77
|
# set :cache, Padrino::Cache.new(:LRUHash) # Keeps cached values in memory
|
|
78
78
|
# set :cache, Padrino::Cache.new(:Memcached) # Uses default server at localhost
|
|
79
|
-
# set :cache, Padrino::Cache.new(:Memcached, '127.0.0.1:11211', :
|
|
80
|
-
# set :cache, Padrino::Cache.new(:Memcached, :
|
|
79
|
+
# set :cache, Padrino::Cache.new(:Memcached, '127.0.0.1:11211', exception_retry_limit: 1)
|
|
80
|
+
# set :cache, Padrino::Cache.new(:Memcached, backend: memcached_or_dalli_instance)
|
|
81
81
|
# set :cache, Padrino::Cache.new(:Redis) # Uses default server at localhost
|
|
82
|
-
# set :cache, Padrino::Cache.new(:Redis, :
|
|
83
|
-
# set :cache, Padrino::Cache.new(:Redis, :
|
|
82
|
+
# set :cache, Padrino::Cache.new(:Redis, host: '127.0.0.1', port: 6379, db: 0)
|
|
83
|
+
# set :cache, Padrino::Cache.new(:Redis, backend: redis_instance)
|
|
84
84
|
# set :cache, Padrino::Cache.new(:Mongo) # Uses default server at localhost
|
|
85
|
-
# set :cache, Padrino::Cache.new(:Mongo, :
|
|
86
|
-
# set :cache, Padrino::Cache.new(:File, :
|
|
85
|
+
# set :cache, Padrino::Cache.new(:Mongo, backend: mongo_client_instance)
|
|
86
|
+
# set :cache, Padrino::Cache.new(:File, dir: Padrino.root('tmp', app_name.to_s, 'cache')) # default choice
|
|
87
87
|
#
|
|
88
88
|
# You can manage your cache from anywhere in your app:
|
|
89
89
|
#
|
|
@@ -99,7 +99,7 @@ module Padrino
|
|
|
99
99
|
app.helpers Padrino::Cache::Helpers::Page
|
|
100
100
|
unless app.respond_to?(:cache)
|
|
101
101
|
cache_dir = Padrino.root('tmp', defined?(app.app_name) ? app.app_name.to_s : '', 'cache')
|
|
102
|
-
app.set :cache, Padrino::Cache.new(:File, :
|
|
102
|
+
app.set :cache, Padrino::Cache.new(:File, dir: cache_dir)
|
|
103
103
|
end
|
|
104
104
|
app.disable :caching unless app.respond_to?(:caching)
|
|
105
105
|
included(app)
|
data/padrino-cache.gemspec
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env gem build
|
|
2
2
|
# encoding: utf-8
|
|
3
3
|
|
|
4
|
-
require File.expand_path(
|
|
4
|
+
require File.expand_path('../padrino-core/lib/padrino-core/version.rb', __dir__)
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
|
-
s.name =
|
|
8
|
-
s.authors = [
|
|
9
|
-
s.email =
|
|
10
|
-
s.summary =
|
|
11
|
-
s.homepage =
|
|
12
|
-
s.description =
|
|
13
|
-
s.required_rubygems_version =
|
|
7
|
+
s.name = 'padrino-cache'
|
|
8
|
+
s.authors = ['Padrino Team', 'Nathan Esquenazi', "Davide D'Agostino", 'Arthur Chiu']
|
|
9
|
+
s.email = 'padrinorb@gmail.com'
|
|
10
|
+
s.summary = 'Page and fragment caching for Padrino'
|
|
11
|
+
s.homepage = 'http://www.padrinorb.com'
|
|
12
|
+
s.description = 'Caching support for memcached, page and fragment'
|
|
13
|
+
s.required_rubygems_version = '>= 1.3.6'
|
|
14
14
|
s.version = Padrino.version
|
|
15
|
-
s.date = Time.now.strftime(
|
|
16
|
-
s.license =
|
|
15
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
|
16
|
+
s.license = 'MIT'
|
|
17
17
|
|
|
18
|
-
s.extra_rdoc_files = Dir[
|
|
18
|
+
s.extra_rdoc_files = Dir['*.rdoc']
|
|
19
19
|
s.files = `git ls-files`.split("\n")
|
|
20
20
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
21
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
22
|
-
s.require_paths = [
|
|
23
|
-
s.rdoc_options = [
|
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
|
22
|
+
s.require_paths = ['lib']
|
|
23
|
+
s.rdoc_options = ['--charset=UTF-8']
|
|
24
24
|
|
|
25
|
-
s.add_runtime_dependency(
|
|
26
|
-
s.add_runtime_dependency(
|
|
27
|
-
s.add_runtime_dependency(
|
|
25
|
+
s.add_runtime_dependency('padrino-core', Padrino.version)
|
|
26
|
+
s.add_runtime_dependency('padrino-helpers', Padrino.version)
|
|
27
|
+
s.add_runtime_dependency('moneta', ['~> 1.6'])
|
|
28
28
|
end
|
data/test/helper.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
ENV['RACK_ENV'] = 'test'
|
|
2
|
-
PADRINO_ROOT =
|
|
2
|
+
PADRINO_ROOT = __dir__ unless defined?(PADRINO_ROOT)
|
|
3
3
|
|
|
4
4
|
require 'minitest/autorun'
|
|
5
5
|
require 'minitest/pride'
|
|
@@ -14,7 +14,7 @@ class Minitest::Spec
|
|
|
14
14
|
# Sets up a Sinatra::Base subclass defined with the block
|
|
15
15
|
# given. Used in setup or individual spec methods to establish
|
|
16
16
|
# the application.
|
|
17
|
-
def mock_app(base=Padrino::Application, &block)
|
|
17
|
+
def mock_app(base = Padrino::Application, &block)
|
|
18
18
|
@app = Sinatra.new(base, &block)
|
|
19
19
|
end
|
|
20
20
|
|
data/test/test_moneta_store.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative 'helper'
|
|
2
2
|
|
|
3
3
|
describe 'Padrino::Cache - Moneta store' do
|
|
4
4
|
def setup
|
|
@@ -10,7 +10,7 @@ describe 'Padrino::Cache - Moneta store' do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
class Foo
|
|
13
|
-
def bar;
|
|
13
|
+
def bar; 'bar'; end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
it "return nil trying to get a value that doesn't exist" do
|
|
@@ -20,7 +20,7 @@ describe 'Padrino::Cache - Moneta store' do
|
|
|
20
20
|
|
|
21
21
|
it 'set and get an object with marshal' do
|
|
22
22
|
Padrino.cache[@test_key] = Foo.new
|
|
23
|
-
assert_equal
|
|
23
|
+
assert_equal 'bar', Padrino.cache[@test_key].bar
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
it 'set and get a nil value' do
|
|
@@ -33,15 +33,15 @@ describe 'Padrino::Cache - Moneta store' do
|
|
|
33
33
|
assert_equal 'foo', Padrino.cache[@test_key]
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
it
|
|
37
|
-
init_time =
|
|
38
|
-
Time.stub(:now, init_time) { Padrino.cache.store(@test_key, 'test', :
|
|
36
|
+
it 'set a value that expires' do
|
|
37
|
+
init_time = Time.now - 20
|
|
38
|
+
Time.stub(:now, init_time) { Padrino.cache.store(@test_key, 'test', expires: 1) }
|
|
39
39
|
Time.stub(:now, init_time + 20) { assert_nil Padrino.cache[@test_key] }
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
it
|
|
43
|
-
Padrino.cache.store('forever', 'cached', :
|
|
44
|
-
2.times {
|
|
42
|
+
it 'be able to cache forever' do
|
|
43
|
+
Padrino.cache.store('forever', 'cached', expires: false)
|
|
44
|
+
2.times { assert_equal 'cached', Padrino.cache['forever'] }
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
it 'delete a value' do
|
data/test/test_padrino_cache.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
require File.expand_path('
|
|
1
|
+
require File.expand_path('helper', __dir__)
|
|
2
2
|
|
|
3
|
-
describe
|
|
3
|
+
describe 'PadrinoCache' do
|
|
4
4
|
after do
|
|
5
|
-
tmp = File.expand_path(
|
|
6
|
-
|
|
5
|
+
tmp = File.expand_path('tmp', __dir__)
|
|
6
|
+
`rm -rf #{tmp}`
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
it 'should cache a fragment' do
|
|
@@ -11,12 +11,12 @@ describe "PadrinoCache" do
|
|
|
11
11
|
mock_app do
|
|
12
12
|
register Padrino::Cache
|
|
13
13
|
enable :caching
|
|
14
|
-
get(
|
|
14
|
+
get('/foo') { cache(:test) { called ? halt(500) : (called = 'test fragment') } }
|
|
15
15
|
end
|
|
16
|
-
get
|
|
16
|
+
get '/foo'
|
|
17
17
|
assert_equal 200, status
|
|
18
18
|
assert_equal 'test fragment', body
|
|
19
|
-
get
|
|
19
|
+
get '/foo'
|
|
20
20
|
assert_equal 200, status
|
|
21
21
|
assert_equal 'test fragment', body
|
|
22
22
|
refute_equal called, false
|
|
@@ -27,12 +27,12 @@ describe "PadrinoCache" do
|
|
|
27
27
|
mock_app do
|
|
28
28
|
register Padrino::Cache
|
|
29
29
|
enable :caching
|
|
30
|
-
get('/foo', :
|
|
30
|
+
get('/foo', cache: true) { called ? halt(500) : (called = 'test page') }
|
|
31
31
|
end
|
|
32
|
-
get
|
|
32
|
+
get '/foo'
|
|
33
33
|
assert_equal 200, status
|
|
34
34
|
assert_equal 'test page', body
|
|
35
|
-
get
|
|
35
|
+
get '/foo'
|
|
36
36
|
assert_equal 200, status
|
|
37
37
|
assert_equal 'test page', body
|
|
38
38
|
refute_equal false, called
|
|
@@ -43,10 +43,10 @@ describe "PadrinoCache" do
|
|
|
43
43
|
mock_app do
|
|
44
44
|
register Padrino::Cache
|
|
45
45
|
enable :caching
|
|
46
|
-
get('/foo', :
|
|
46
|
+
get('/foo', cache: true) { called_times += 1; called_times.to_s }
|
|
47
47
|
end
|
|
48
|
-
head
|
|
49
|
-
head
|
|
48
|
+
head '/foo'
|
|
49
|
+
head '/foo'
|
|
50
50
|
assert_equal 1, called_times
|
|
51
51
|
end
|
|
52
52
|
|
|
@@ -55,11 +55,11 @@ describe "PadrinoCache" do
|
|
|
55
55
|
mock_app do
|
|
56
56
|
register Padrino::Cache
|
|
57
57
|
enable :caching
|
|
58
|
-
post('/foo', :
|
|
58
|
+
post('/foo', cache: true) { called_times += 1; called_times.to_s }
|
|
59
59
|
end
|
|
60
|
-
post
|
|
60
|
+
post '/foo'
|
|
61
61
|
assert_equal 1, called_times
|
|
62
|
-
post
|
|
62
|
+
post '/foo'
|
|
63
63
|
assert_equal 2, called_times
|
|
64
64
|
end
|
|
65
65
|
|
|
@@ -68,11 +68,11 @@ describe "PadrinoCache" do
|
|
|
68
68
|
mock_app do
|
|
69
69
|
register Padrino::Cache
|
|
70
70
|
enable :caching
|
|
71
|
-
delete('/foo', :
|
|
71
|
+
delete('/foo', cache: true) { called_times += 1; called_times.to_s }
|
|
72
72
|
end
|
|
73
|
-
delete
|
|
73
|
+
delete '/foo'
|
|
74
74
|
assert_equal 1, called_times
|
|
75
|
-
delete
|
|
75
|
+
delete '/foo'
|
|
76
76
|
assert_equal 2, called_times
|
|
77
77
|
end
|
|
78
78
|
|
|
@@ -81,11 +81,11 @@ describe "PadrinoCache" do
|
|
|
81
81
|
mock_app do
|
|
82
82
|
register Padrino::Cache
|
|
83
83
|
enable :caching
|
|
84
|
-
put('/foo', :
|
|
84
|
+
put('/foo', cache: true) { called_times += 1; called_times.to_s }
|
|
85
85
|
end
|
|
86
|
-
put
|
|
86
|
+
put '/foo'
|
|
87
87
|
assert_equal 1, called_times
|
|
88
|
-
put
|
|
88
|
+
put '/foo'
|
|
89
89
|
assert_equal 2, called_times
|
|
90
90
|
end
|
|
91
91
|
|
|
@@ -94,14 +94,14 @@ describe "PadrinoCache" do
|
|
|
94
94
|
mock_app do
|
|
95
95
|
register Padrino::Cache
|
|
96
96
|
enable :caching
|
|
97
|
-
get('/foo', :
|
|
98
|
-
get('/delete_foo'){ expire('/foo') }
|
|
97
|
+
get('/foo', cache: true) { called ? 'test page again' : (called = 'test page') }
|
|
98
|
+
get('/delete_foo') { expire('/foo') }
|
|
99
99
|
end
|
|
100
|
-
get
|
|
100
|
+
get '/foo'
|
|
101
101
|
assert_equal 200, status
|
|
102
102
|
assert_equal 'test page', body
|
|
103
|
-
get
|
|
104
|
-
get
|
|
103
|
+
get '/delete_foo'
|
|
104
|
+
get '/foo'
|
|
105
105
|
assert_equal 200, status
|
|
106
106
|
assert_equal 'test page again', body
|
|
107
107
|
refute_equal false, called
|
|
@@ -112,7 +112,7 @@ describe "PadrinoCache" do
|
|
|
112
112
|
mock_app do
|
|
113
113
|
register Padrino::Cache
|
|
114
114
|
enable :caching
|
|
115
|
-
get '/foo', :
|
|
115
|
+
get '/foo', cache: true do
|
|
116
116
|
if called
|
|
117
117
|
"you'll never see me"
|
|
118
118
|
else
|
|
@@ -123,7 +123,7 @@ describe "PadrinoCache" do
|
|
|
123
123
|
end
|
|
124
124
|
end
|
|
125
125
|
|
|
126
|
-
get '/bar', :
|
|
126
|
+
get '/bar', cache: true do
|
|
127
127
|
if called
|
|
128
128
|
cache_key :bar
|
|
129
129
|
called = 'bar'
|
|
@@ -134,18 +134,18 @@ describe "PadrinoCache" do
|
|
|
134
134
|
end
|
|
135
135
|
end
|
|
136
136
|
end
|
|
137
|
-
get
|
|
137
|
+
get '/foo'
|
|
138
138
|
assert_equal 200, status
|
|
139
139
|
assert_equal 'foo', body
|
|
140
140
|
assert_equal 'foo', @app.cache[:foo][:body]
|
|
141
|
-
get
|
|
141
|
+
get '/foo'
|
|
142
142
|
assert_equal 'foo', body
|
|
143
143
|
|
|
144
|
-
get
|
|
144
|
+
get '/bar'
|
|
145
145
|
assert_equal 200, status
|
|
146
146
|
assert_equal 'bar', body
|
|
147
147
|
assert_equal 'bar', @app.cache[:bar][:body]
|
|
148
|
-
get
|
|
148
|
+
get '/bar'
|
|
149
149
|
assert_equal 'bar', body
|
|
150
150
|
end
|
|
151
151
|
|
|
@@ -154,14 +154,14 @@ describe "PadrinoCache" do
|
|
|
154
154
|
mock_app do
|
|
155
155
|
register Padrino::Cache
|
|
156
156
|
enable :caching
|
|
157
|
-
get(:foo, :
|
|
158
|
-
get(:delete_foo, :
|
|
157
|
+
get(:foo, with: :id, cache: true) { called ? 'test page again' : (called = 'test page') }
|
|
158
|
+
get(:delete_foo, with: :id) { expire(:foo, params[:id]) }
|
|
159
159
|
end
|
|
160
|
-
get
|
|
160
|
+
get '/foo/12'
|
|
161
161
|
assert_equal 200, status
|
|
162
162
|
assert_equal 'test page', body
|
|
163
|
-
get
|
|
164
|
-
get
|
|
163
|
+
get '/delete_foo/12'
|
|
164
|
+
get '/foo/12'
|
|
165
165
|
assert_equal 200, status
|
|
166
166
|
assert_equal 'test page again', body
|
|
167
167
|
end
|
|
@@ -169,16 +169,16 @@ describe "PadrinoCache" do
|
|
|
169
169
|
it 'should allow controller-wide caching' do
|
|
170
170
|
called = false
|
|
171
171
|
mock_app do
|
|
172
|
-
controller :
|
|
172
|
+
controller cache: true do
|
|
173
173
|
register Padrino::Cache
|
|
174
174
|
enable :caching
|
|
175
|
-
get(
|
|
175
|
+
get('/foo') { called ? halt(500) : (called = 'test') }
|
|
176
176
|
end
|
|
177
177
|
end
|
|
178
|
-
get
|
|
178
|
+
get '/foo'
|
|
179
179
|
assert_equal 200, status
|
|
180
180
|
assert_equal 'test', body
|
|
181
|
-
get
|
|
181
|
+
get '/foo'
|
|
182
182
|
assert_equal 200, status
|
|
183
183
|
assert_equal 'test', body
|
|
184
184
|
end
|
|
@@ -187,19 +187,19 @@ describe "PadrinoCache" do
|
|
|
187
187
|
called = false
|
|
188
188
|
mock_app do
|
|
189
189
|
register Padrino::Cache
|
|
190
|
-
controller :
|
|
190
|
+
controller cache: true do
|
|
191
191
|
enable :caching
|
|
192
192
|
expires 1
|
|
193
|
-
get(
|
|
193
|
+
get('/foo') { called ? halt(500) : (called = 'test') }
|
|
194
194
|
end
|
|
195
195
|
end
|
|
196
|
-
get
|
|
196
|
+
get '/foo'
|
|
197
197
|
assert_equal 200, status
|
|
198
198
|
assert_equal 'test', body
|
|
199
|
-
get
|
|
199
|
+
get '/foo'
|
|
200
200
|
assert_equal 200, status
|
|
201
201
|
assert_equal 'test', body
|
|
202
|
-
Time.stub(:now, Time.now + 2) { get
|
|
202
|
+
Time.stub(:now, Time.now + 2) { get '/foo' }
|
|
203
203
|
assert_equal 500, status
|
|
204
204
|
end
|
|
205
205
|
|
|
@@ -208,14 +208,14 @@ describe "PadrinoCache" do
|
|
|
208
208
|
mock_app do
|
|
209
209
|
register Padrino::Cache
|
|
210
210
|
enable :caching
|
|
211
|
-
controller :
|
|
212
|
-
get(
|
|
211
|
+
controller cache: true do
|
|
212
|
+
get('/foo', cache: false) { called ? 'test again' : (called = 'test') }
|
|
213
213
|
end
|
|
214
214
|
end
|
|
215
|
-
get
|
|
215
|
+
get '/foo'
|
|
216
216
|
assert_equal 200, status
|
|
217
217
|
assert_equal 'test', body
|
|
218
|
-
get
|
|
218
|
+
get '/foo'
|
|
219
219
|
assert_equal 200, status
|
|
220
220
|
assert_equal 'test again', body
|
|
221
221
|
end
|
|
@@ -225,20 +225,20 @@ describe "PadrinoCache" do
|
|
|
225
225
|
mock_app do
|
|
226
226
|
register Padrino::Cache
|
|
227
227
|
enable :caching
|
|
228
|
-
controller :
|
|
229
|
-
get(
|
|
228
|
+
controller cache: true do
|
|
229
|
+
get('/foo') do
|
|
230
230
|
expires 1
|
|
231
231
|
called ? 'test again' : (called = 'test')
|
|
232
|
-
|
|
232
|
+
end
|
|
233
233
|
end
|
|
234
234
|
end
|
|
235
|
-
get
|
|
235
|
+
get '/foo'
|
|
236
236
|
assert_equal 200, status
|
|
237
237
|
assert_equal 'test', body
|
|
238
|
-
get
|
|
238
|
+
get '/foo'
|
|
239
239
|
assert_equal 200, status
|
|
240
240
|
assert_equal 'test', body
|
|
241
|
-
Time.stub(:now, Time.now + 3) { get
|
|
241
|
+
Time.stub(:now, Time.now + 3) { get '/foo' }
|
|
242
242
|
assert_equal 200, status
|
|
243
243
|
assert_equal 'test again', body
|
|
244
244
|
end
|
|
@@ -249,21 +249,21 @@ describe "PadrinoCache" do
|
|
|
249
249
|
register Padrino::Cache
|
|
250
250
|
enable :caching
|
|
251
251
|
controller do
|
|
252
|
-
get(
|
|
252
|
+
get('/foo') do
|
|
253
253
|
expires 1
|
|
254
|
-
cache(:test, :
|
|
254
|
+
cache(:test, expires: 2) do
|
|
255
255
|
called ? 'test again' : (called = 'test')
|
|
256
256
|
end
|
|
257
|
-
|
|
257
|
+
end
|
|
258
258
|
end
|
|
259
259
|
end
|
|
260
|
-
get
|
|
260
|
+
get '/foo'
|
|
261
261
|
assert_equal 200, status
|
|
262
262
|
assert_equal 'test', body
|
|
263
|
-
get
|
|
263
|
+
get '/foo'
|
|
264
264
|
assert_equal 200, status
|
|
265
265
|
assert_equal 'test', body
|
|
266
|
-
Time.stub(:now, Time.now + 3) { get
|
|
266
|
+
Time.stub(:now, Time.now + 3) { get '/foo' }
|
|
267
267
|
assert_equal 200, status
|
|
268
268
|
assert_equal 'test again', body
|
|
269
269
|
end
|
|
@@ -273,14 +273,14 @@ describe "PadrinoCache" do
|
|
|
273
273
|
mock_app do
|
|
274
274
|
register Padrino::Cache
|
|
275
275
|
disable :caching
|
|
276
|
-
controller :
|
|
277
|
-
get(
|
|
276
|
+
controller cache: true do
|
|
277
|
+
get('/foo') { called ? halt(500) : (called = 'test') }
|
|
278
278
|
end
|
|
279
279
|
end
|
|
280
|
-
get
|
|
280
|
+
get '/foo'
|
|
281
281
|
assert_equal 200, status
|
|
282
282
|
assert_equal 'test', body
|
|
283
|
-
get
|
|
283
|
+
get '/foo'
|
|
284
284
|
assert_equal 500, status
|
|
285
285
|
end
|
|
286
286
|
|
|
@@ -288,10 +288,10 @@ describe "PadrinoCache" do
|
|
|
288
288
|
mock_app do
|
|
289
289
|
register Padrino::Cache
|
|
290
290
|
enable :caching
|
|
291
|
-
get(
|
|
292
|
-
get(
|
|
291
|
+
get('/404', cache: true) { not_found }
|
|
292
|
+
get('/503', cache: true) { error 503 }
|
|
293
293
|
not_found { 'fancy 404' }
|
|
294
|
-
error(
|
|
294
|
+
error(503) { 'fancy 503' }
|
|
295
295
|
end
|
|
296
296
|
get '/404'
|
|
297
297
|
assert_equal 'fancy 404', body
|
|
@@ -318,7 +318,7 @@ describe "PadrinoCache" do
|
|
|
318
318
|
param = params[:test] || 'none'
|
|
319
319
|
cache_key "foo?#{param}"
|
|
320
320
|
end
|
|
321
|
-
get '/foo/:test', :
|
|
321
|
+
get '/foo/:test', cache: true do
|
|
322
322
|
param = params[:test] || 'none'
|
|
323
323
|
call_count += 1
|
|
324
324
|
"foo?#{param}"
|
|
@@ -342,7 +342,7 @@ describe "PadrinoCache" do
|
|
|
342
342
|
register Padrino::Cache
|
|
343
343
|
enable :caching
|
|
344
344
|
|
|
345
|
-
get '/foo', :
|
|
345
|
+
get '/foo', cache: true do
|
|
346
346
|
cache_key { "key #{params[:id]}" }
|
|
347
347
|
call_count += 1
|
|
348
348
|
params[:id]
|
|
@@ -363,7 +363,7 @@ describe "PadrinoCache" do
|
|
|
363
363
|
register Padrino::Cache
|
|
364
364
|
enable :caching
|
|
365
365
|
|
|
366
|
-
get '/foo', :
|
|
366
|
+
get '/foo', cache: true do
|
|
367
367
|
cache_key(:some_key) { "key #{params[:id]}" }
|
|
368
368
|
end
|
|
369
369
|
end
|
|
@@ -376,7 +376,7 @@ describe "PadrinoCache" do
|
|
|
376
376
|
mock_app do
|
|
377
377
|
register Padrino::Cache
|
|
378
378
|
enable :caching
|
|
379
|
-
get '/foo', :
|
|
379
|
+
get '/foo', cache: true do
|
|
380
380
|
content_type :json
|
|
381
381
|
if called
|
|
382
382
|
"you'll never see me"
|
|
@@ -388,13 +388,13 @@ describe "PadrinoCache" do
|
|
|
388
388
|
end
|
|
389
389
|
end
|
|
390
390
|
end
|
|
391
|
-
get
|
|
391
|
+
get '/foo'
|
|
392
392
|
assert_equal 200, status
|
|
393
393
|
assert_equal '{"foo":"bar"}', body
|
|
394
394
|
assert_equal '{"foo":"bar"}', @app.cache[:foo][:body]
|
|
395
|
-
get
|
|
395
|
+
get '/foo'
|
|
396
396
|
assert_equal '{"foo":"bar"}', body
|
|
397
|
-
assert_match
|
|
397
|
+
assert_match(/json/, last_response.content_type)
|
|
398
398
|
end
|
|
399
399
|
|
|
400
400
|
it 'should cache an object' do
|
|
@@ -407,7 +407,7 @@ describe "PadrinoCache" do
|
|
|
407
407
|
2.times do
|
|
408
408
|
result = cache_object 'object1' do
|
|
409
409
|
counter += 1
|
|
410
|
-
{ :
|
|
410
|
+
{ foo: 'bar' }
|
|
411
411
|
end
|
|
412
412
|
end
|
|
413
413
|
result[:foo].to_s
|
|
@@ -425,35 +425,35 @@ describe "PadrinoCache" do
|
|
|
425
425
|
mock_app do
|
|
426
426
|
register Padrino::Cache
|
|
427
427
|
enable :caching
|
|
428
|
-
controller :
|
|
429
|
-
get(
|
|
428
|
+
controller cache: true do
|
|
429
|
+
get('/foo') do
|
|
430
430
|
expires 1
|
|
431
431
|
called_times_a += 1
|
|
432
432
|
called_times_b.to_s
|
|
433
433
|
end
|
|
434
|
-
get(
|
|
434
|
+
get('/bar') do
|
|
435
435
|
expires 3
|
|
436
436
|
called_times_b += 1
|
|
437
437
|
called_times_b.to_s
|
|
438
438
|
end
|
|
439
439
|
end
|
|
440
440
|
end
|
|
441
|
-
Time.stub(:now, Time.now) { get
|
|
441
|
+
Time.stub(:now, Time.now) { get '/foo'; get '/bar' }
|
|
442
442
|
assert_equal 1, called_times_a
|
|
443
443
|
assert_equal 1, called_times_b
|
|
444
|
-
Time.stub(:now, Time.now + 0.5) { get
|
|
444
|
+
Time.stub(:now, Time.now + 0.5) { get '/foo'; get '/bar' }
|
|
445
445
|
assert_equal 1, called_times_a
|
|
446
446
|
assert_equal 1, called_times_b
|
|
447
|
-
Time.stub(:now, Time.now + 2) { get
|
|
447
|
+
Time.stub(:now, Time.now + 2) { get '/foo'; get '/bar' }
|
|
448
448
|
assert_equal 2, called_times_a
|
|
449
449
|
assert_equal 1, called_times_b
|
|
450
|
-
Time.stub(:now, Time.now + 2.5) { get
|
|
450
|
+
Time.stub(:now, Time.now + 2.5) { get '/foo'; get '/bar' }
|
|
451
451
|
assert_equal 2, called_times_a
|
|
452
452
|
assert_equal 1, called_times_b
|
|
453
|
-
Time.stub(:now, Time.now + 4) { get
|
|
453
|
+
Time.stub(:now, Time.now + 4) { get '/foo'; get '/bar' }
|
|
454
454
|
assert_equal 3, called_times_a
|
|
455
455
|
assert_equal 2, called_times_b
|
|
456
|
-
Time.stub(:now, Time.now + 5.5) { get
|
|
456
|
+
Time.stub(:now, Time.now + 5.5) { get '/foo'; get '/bar' }
|
|
457
457
|
assert_equal 4, called_times_a
|
|
458
458
|
assert_equal 2, called_times_b
|
|
459
459
|
end
|
|
@@ -474,18 +474,16 @@ describe "PadrinoCache" do
|
|
|
474
474
|
end
|
|
475
475
|
|
|
476
476
|
adapter = @app.cache.adapter
|
|
477
|
-
while adapter.respond_to?
|
|
478
|
-
adapter = adapter.adapter
|
|
479
|
-
end
|
|
477
|
+
adapter = adapter.adapter while adapter.respond_to?(:adapter)
|
|
480
478
|
assert_kind_of Moneta::Adapters::Memory, adapter
|
|
481
479
|
end
|
|
482
480
|
|
|
483
|
-
it
|
|
481
|
+
it 'should check key existence' do
|
|
484
482
|
count1, count2 = 0, 0
|
|
485
483
|
mock_app do
|
|
486
484
|
register Padrino::Cache
|
|
487
485
|
enable :caching
|
|
488
|
-
get
|
|
486
|
+
get '/' do
|
|
489
487
|
cache(:foo) do
|
|
490
488
|
count1 += 1
|
|
491
489
|
nil
|
|
@@ -493,7 +491,7 @@ describe "PadrinoCache" do
|
|
|
493
491
|
count1.inspect
|
|
494
492
|
end
|
|
495
493
|
|
|
496
|
-
get
|
|
494
|
+
get '/object' do
|
|
497
495
|
cache_object(:bar) do
|
|
498
496
|
count2 += 1
|
|
499
497
|
nil
|
|
@@ -501,24 +499,24 @@ describe "PadrinoCache" do
|
|
|
501
499
|
count2.inspect
|
|
502
500
|
end
|
|
503
501
|
end
|
|
504
|
-
2.times { get
|
|
505
|
-
assert_equal
|
|
506
|
-
2.times { get
|
|
507
|
-
assert_equal
|
|
502
|
+
2.times { get '/' }
|
|
503
|
+
assert_equal '1', body
|
|
504
|
+
2.times { get '/object' }
|
|
505
|
+
assert_equal '1', body
|
|
508
506
|
end
|
|
509
507
|
|
|
510
508
|
it 'should cache full mime type of content_type' do
|
|
511
509
|
mock_app do
|
|
512
510
|
register Padrino::Cache
|
|
513
511
|
enable :caching
|
|
514
|
-
get '/foo', :
|
|
515
|
-
content_type :json, :
|
|
512
|
+
get '/foo', cache: true do
|
|
513
|
+
content_type :json, charset: 'utf-8'
|
|
516
514
|
'{}'
|
|
517
515
|
end
|
|
518
516
|
end
|
|
519
|
-
get
|
|
517
|
+
get '/foo'
|
|
520
518
|
assert_equal 'application/json;charset=utf-8', last_response.content_type
|
|
521
|
-
get
|
|
519
|
+
get '/foo'
|
|
522
520
|
assert_equal 'application/json;charset=utf-8', last_response.content_type
|
|
523
521
|
end
|
|
524
522
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: padrino-cache
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.16.0
|
|
4
|
+
version: 0.16.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Padrino Team
|
|
@@ -11,7 +11,7 @@ authors:
|
|
|
11
11
|
autorequire:
|
|
12
12
|
bindir: bin
|
|
13
13
|
cert_chain: []
|
|
14
|
-
date: 2025-
|
|
14
|
+
date: 2025-12-02 00:00:00.000000000 Z
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
17
17
|
name: padrino-core
|
|
@@ -19,28 +19,28 @@ dependencies:
|
|
|
19
19
|
requirements:
|
|
20
20
|
- - '='
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: 0.16.0
|
|
22
|
+
version: 0.16.0
|
|
23
23
|
type: :runtime
|
|
24
24
|
prerelease: false
|
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
26
|
requirements:
|
|
27
27
|
- - '='
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: 0.16.0
|
|
29
|
+
version: 0.16.0
|
|
30
30
|
- !ruby/object:Gem::Dependency
|
|
31
31
|
name: padrino-helpers
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
|
33
33
|
requirements:
|
|
34
34
|
- - '='
|
|
35
35
|
- !ruby/object:Gem::Version
|
|
36
|
-
version: 0.16.0
|
|
36
|
+
version: 0.16.0
|
|
37
37
|
type: :runtime
|
|
38
38
|
prerelease: false
|
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
|
40
40
|
requirements:
|
|
41
41
|
- - '='
|
|
42
42
|
- !ruby/object:Gem::Version
|
|
43
|
-
version: 0.16.0
|
|
43
|
+
version: 0.16.0
|
|
44
44
|
- !ruby/object:Gem::Dependency
|
|
45
45
|
name: moneta
|
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -93,9 +93,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
93
93
|
version: '0'
|
|
94
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
requirements:
|
|
96
|
-
- - "
|
|
96
|
+
- - ">="
|
|
97
97
|
- !ruby/object:Gem::Version
|
|
98
|
-
version: 1.3.
|
|
98
|
+
version: 1.3.6
|
|
99
99
|
requirements: []
|
|
100
100
|
rubygems_version: 3.4.19
|
|
101
101
|
signing_key:
|