padrino-cache 0.12.9 → 0.13.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/padrino-cache/helpers/cache_object.rb +1 -2
- data/lib/padrino-cache/helpers/fragment.rb +2 -3
- data/lib/padrino-cache/helpers/page.rb +1 -6
- data/lib/padrino-cache.rb +1 -7
- data/test/test_padrino_cache.rb +1 -47
- metadata +17 -17
- data/lib/padrino-cache/legacy_store.rb +0 -68
- data/test/test_legacy_store.rb +0 -53
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
YTgzNTJiNDRiNTA2MDdhZjk1OGY4MTg0NzRlZDU0ZTVmZmUwNjE3YQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 788f55f9c8d59072188545b3578a53250d12aeca
|
4
|
+
data.tar.gz: a8fadd17541f1b35234d8771e5bd90ef7bb38bc8
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NDkwMjExMzBjMGQwODhlZjFkM2NkZjkxYWMxZmI3MTk5NDFiOWU0YTFjMDM1
|
11
|
-
YTE0MzFlNTIxYTgyZDBjODViZGIxMmJiYzYyYjAzYjRiZGU1MDk=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MTU0MTQ0NzdmYTU0Mzg1Y2YyZWFmMTEwMmE1MTZmY2M5NDdkOTRjZGRiMTY0
|
14
|
-
YmFiZGE0MzNjNjhhYjAwMDMyMjQ3NDMwYmZjNmNjNWUyZWY4NmVjMGQ2ZDg2
|
15
|
-
ZWI4Y2RhZmFhZTdlNWNmMDAyOGNkMWFkYjliNDg3MWUyMmE4Mzk=
|
6
|
+
metadata.gz: ddc3499620444450fbbb78332dad102cd2069cb2e34eb072fb7ddfab58bf12672b8860acb8937c1970d08a80d13e9f3dfb3b3f858f03bc0e42cf358ab2a6009f
|
7
|
+
data.tar.gz: bae429f3ee32d8976cc8fb748665586b4e675578914cc89d5240b5aee619b65638a4207abf2843ed1cb845e704cb12cf7c97224484aa4a371ee040a7b0dbadf9
|
@@ -5,8 +5,7 @@ module Padrino
|
|
5
5
|
def cache_object(key, opts = {})
|
6
6
|
if settings.caching?
|
7
7
|
began_at = Time.now
|
8
|
-
if settings.cache
|
9
|
-
value = settings.cache[key.to_s]
|
8
|
+
if value = settings.cache[key.to_s]
|
10
9
|
logger.debug "GET Object", began_at, key.to_s if defined?(logger)
|
11
10
|
else
|
12
11
|
value = yield
|
@@ -51,10 +51,9 @@ module Padrino
|
|
51
51
|
def cache(key, opts = {}, &block)
|
52
52
|
if settings.caching?
|
53
53
|
began_at = Time.now
|
54
|
-
if settings.cache
|
55
|
-
value = settings.cache[key.to_s]
|
54
|
+
if value = settings.cache[key.to_s]
|
56
55
|
logger.debug "GET Fragment", began_at, key.to_s if defined?(logger)
|
57
|
-
concat_content(value.
|
56
|
+
concat_content(value.html_safe)
|
58
57
|
else
|
59
58
|
value = capture_html(&block)
|
60
59
|
settings.cache.store(key.to_s, value, opts)
|
@@ -63,11 +63,6 @@ module Padrino
|
|
63
63
|
@route.cache_expires = time
|
64
64
|
end
|
65
65
|
|
66
|
-
def expires_in(time)
|
67
|
-
warn 'expires_in has been deprecated in favour of expires'
|
68
|
-
expires(time)
|
69
|
-
end
|
70
|
-
|
71
66
|
##
|
72
67
|
# This helper is used within a route or route to indicate the name in the cache.
|
73
68
|
#
|
@@ -135,7 +130,7 @@ module Padrino
|
|
135
130
|
|
136
131
|
content = {
|
137
132
|
:body => @_response_buffer,
|
138
|
-
:content_type =>
|
133
|
+
:content_type => @_content_type
|
139
134
|
}
|
140
135
|
|
141
136
|
settings.cache.store(route_cache_key, content, :expires => cache_expires)
|
data/lib/padrino-cache.rb
CHANGED
@@ -3,7 +3,6 @@ require 'padrino-core'
|
|
3
3
|
require 'padrino-helpers'
|
4
4
|
FileSet.glob_require('padrino-cache/{helpers}/*.rb', __FILE__)
|
5
5
|
require 'moneta'
|
6
|
-
require 'padrino-cache/legacy_store'
|
7
6
|
|
8
7
|
module Padrino
|
9
8
|
class << self
|
@@ -118,12 +117,7 @@ module Padrino
|
|
118
117
|
def self.new(name, options = {})
|
119
118
|
# Activate expiration by default
|
120
119
|
options[:expires] = true unless options.include?(:expires)
|
121
|
-
|
122
|
-
Moneta.build do
|
123
|
-
# Use proxy to support deprecated Padrino interface
|
124
|
-
use LegacyStore
|
125
|
-
adapter a
|
126
|
-
end
|
120
|
+
Moneta.new(name, options)
|
127
121
|
end
|
128
122
|
|
129
123
|
Padrino.cache = Padrino::Cache.new(:LRUHash)
|
data/test/test_padrino_cache.rb
CHANGED
@@ -473,52 +473,6 @@ describe "PadrinoCache" do
|
|
473
473
|
register Padrino::Cache
|
474
474
|
end
|
475
475
|
|
476
|
-
|
477
|
-
while adapter.respond_to? :adapter
|
478
|
-
adapter = adapter.adapter
|
479
|
-
end
|
480
|
-
assert_kind_of Moneta::Adapters::Memory, adapter
|
481
|
-
end
|
482
|
-
|
483
|
-
it "should check key existence" do
|
484
|
-
count1, count2 = 0, 0
|
485
|
-
mock_app do
|
486
|
-
register Padrino::Cache
|
487
|
-
enable :caching
|
488
|
-
get "/" do
|
489
|
-
cache(:foo) do
|
490
|
-
count1 += 1
|
491
|
-
nil
|
492
|
-
end
|
493
|
-
count1.inspect
|
494
|
-
end
|
495
|
-
|
496
|
-
get "/object" do
|
497
|
-
cache_object(:bar) do
|
498
|
-
count2 += 1
|
499
|
-
nil
|
500
|
-
end
|
501
|
-
count2.inspect
|
502
|
-
end
|
503
|
-
end
|
504
|
-
2.times { get "/" }
|
505
|
-
assert_equal "1", body
|
506
|
-
2.times { get "/object" }
|
507
|
-
assert_equal "1", body
|
508
|
-
end
|
509
|
-
|
510
|
-
it 'should cache full mime type of content_type' do
|
511
|
-
mock_app do
|
512
|
-
register Padrino::Cache
|
513
|
-
enable :caching
|
514
|
-
get '/foo', :cache => true do
|
515
|
-
content_type :json, :charset => 'utf-8'
|
516
|
-
'{}'
|
517
|
-
end
|
518
|
-
end
|
519
|
-
get "/foo"
|
520
|
-
assert_equal 'application/json;charset=utf-8', last_response.content_type
|
521
|
-
get "/foo"
|
522
|
-
assert_equal 'application/json;charset=utf-8', last_response.content_type
|
476
|
+
assert @app.cache.adapter.adapter.is_a?(Moneta::Adapters::Memory)
|
523
477
|
end
|
524
478
|
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.
|
4
|
+
version: 0.13.0.beta1
|
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:
|
14
|
+
date: 2015-02-22 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: padrino-core
|
@@ -19,44 +19,42 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - '='
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.
|
22
|
+
version: 0.13.0.beta1
|
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.
|
29
|
+
version: 0.13.0.beta1
|
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.
|
36
|
+
version: 0.13.0.beta1
|
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.
|
43
|
+
version: 0.13.0.beta1
|
44
44
|
- !ruby/object:Gem::Dependency
|
45
45
|
name: moneta
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|
47
47
|
requirements:
|
48
48
|
- - ~>
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version:
|
51
|
-
MC43LjA=
|
50
|
+
version: 0.7.0
|
52
51
|
type: :runtime
|
53
52
|
prerelease: false
|
54
53
|
version_requirements: !ruby/object:Gem::Requirement
|
55
54
|
requirements:
|
56
55
|
- - ~>
|
57
56
|
- !ruby/object:Gem::Version
|
58
|
-
version:
|
59
|
-
MC43LjA=
|
57
|
+
version: 0.7.0
|
60
58
|
description: Caching support for memcached, page and fragment
|
61
59
|
email: padrinorb@gmail.com
|
62
60
|
executables: []
|
@@ -75,10 +73,8 @@ files:
|
|
75
73
|
- lib/padrino-cache/helpers/cache_store.rb
|
76
74
|
- lib/padrino-cache/helpers/fragment.rb
|
77
75
|
- lib/padrino-cache/helpers/page.rb
|
78
|
-
- lib/padrino-cache/legacy_store.rb
|
79
76
|
- padrino-cache.gemspec
|
80
77
|
- test/helper.rb
|
81
|
-
- test/test_legacy_store.rb
|
82
78
|
- test/test_moneta_store.rb
|
83
79
|
- test/test_padrino_cache.rb
|
84
80
|
homepage: http://www.padrinorb.com
|
@@ -92,18 +88,22 @@ require_paths:
|
|
92
88
|
- lib
|
93
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
94
90
|
requirements:
|
95
|
-
- -
|
91
|
+
- - '>='
|
96
92
|
- !ruby/object:Gem::Version
|
97
93
|
version: '0'
|
98
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
95
|
requirements:
|
100
|
-
- -
|
96
|
+
- - '>'
|
101
97
|
- !ruby/object:Gem::Version
|
102
|
-
version: 1.3.
|
98
|
+
version: 1.3.1
|
103
99
|
requirements: []
|
104
100
|
rubyforge_project: padrino-cache
|
105
|
-
rubygems_version: 2.6
|
101
|
+
rubygems_version: 2.0.6
|
106
102
|
signing_key:
|
107
103
|
specification_version: 4
|
108
104
|
summary: Page and fragment caching for Padrino
|
109
|
-
test_files:
|
105
|
+
test_files:
|
106
|
+
- test/helper.rb
|
107
|
+
- test/test_moneta_store.rb
|
108
|
+
- test/test_padrino_cache.rb
|
109
|
+
has_rdoc:
|
@@ -1,68 +0,0 @@
|
|
1
|
-
module Padrino
|
2
|
-
module Cache
|
3
|
-
class LegacyStore < Moneta::Proxy
|
4
|
-
##
|
5
|
-
# Return the a value for the given key
|
6
|
-
#
|
7
|
-
# @param [String] key
|
8
|
-
# cache key
|
9
|
-
#
|
10
|
-
# @example
|
11
|
-
# # with MyApp.cache.set('records', records)
|
12
|
-
# MyApp.cache.get('records')
|
13
|
-
#
|
14
|
-
# @api public
|
15
|
-
def get(key)
|
16
|
-
warn 'cache.get(key) has been deprecated in favour of cache[key]'
|
17
|
-
self[key]
|
18
|
-
end
|
19
|
-
|
20
|
-
##
|
21
|
-
# Set the value for a given key and optionally with an expire time
|
22
|
-
# Default expiry time is 86400.
|
23
|
-
#
|
24
|
-
# @param [String] key
|
25
|
-
# cache key
|
26
|
-
# @param value
|
27
|
-
# value of cache key
|
28
|
-
#
|
29
|
-
# @example
|
30
|
-
# MyApp.cache.set('records', records)
|
31
|
-
# MyApp.cache.set('records', records, :expires => 30) # => 30 seconds
|
32
|
-
#
|
33
|
-
# @api public
|
34
|
-
def set(key, value, opts = nil)
|
35
|
-
warn opts ? 'cache.set(key, value, opts) has been deprecated in favour of cache.store(key, value, opts)' :
|
36
|
-
'cache.set(key, value) has been deprecated in favour of cache[key] = value'
|
37
|
-
store(key, value, opts || {})
|
38
|
-
end
|
39
|
-
|
40
|
-
##
|
41
|
-
# Reinitialize your cache
|
42
|
-
#
|
43
|
-
# @example
|
44
|
-
# # with: MyApp.cache.set('records', records)
|
45
|
-
# MyApp.cache.flush
|
46
|
-
# MyApp.cache.get('records') # => nil
|
47
|
-
#
|
48
|
-
# @api public
|
49
|
-
def flush
|
50
|
-
warn 'cache.flush has been deprecated in favour of cache.clear'
|
51
|
-
clear
|
52
|
-
end
|
53
|
-
|
54
|
-
# (see Moneta::Proxy#store)
|
55
|
-
def store(key, value, options = {})
|
56
|
-
if options[:expires_in]
|
57
|
-
warn 'Option :expires_in has been deprecated in favour of :expires'
|
58
|
-
options[:expires] = options.delete(:expires_in).to_i
|
59
|
-
end
|
60
|
-
if options[:expires] && options[:expires] < 0
|
61
|
-
warn 'The use of negative expiration values is deprecated, use :expires => false'
|
62
|
-
options[:expires] = false
|
63
|
-
end
|
64
|
-
adapter.store(key, value, options)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
data/test/test_legacy_store.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
-
|
3
|
-
describe Padrino::Cache::LegacyStore do
|
4
|
-
def setup
|
5
|
-
@test_key = "val_#{Time.now.to_i}"
|
6
|
-
end
|
7
|
-
|
8
|
-
def teardown
|
9
|
-
Padrino.cache.clear
|
10
|
-
end
|
11
|
-
|
12
|
-
class Foo
|
13
|
-
def bar; "bar"; end
|
14
|
-
end
|
15
|
-
|
16
|
-
it "return nil trying to get a value that doesn't exist" do
|
17
|
-
Padrino.cache.flush
|
18
|
-
assert_equal nil, Padrino.cache.get(@test_key)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'set and get an object with marshal' do
|
22
|
-
Padrino.cache.set(@test_key, Foo.new)
|
23
|
-
assert_equal "bar", Padrino.cache.get(@test_key).bar
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'set and get a nil value' do
|
27
|
-
Padrino.cache.set(@test_key, nil)
|
28
|
-
assert_equal '', Padrino.cache.get(@test_key).to_s
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'set and get a raw value' do
|
32
|
-
Padrino.cache.set(@test_key, 'foo')
|
33
|
-
assert_equal 'foo', Padrino.cache.get(@test_key)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "set a value that expires" do
|
37
|
-
init_time = ( Time.now - 20 )
|
38
|
-
Time.stub(:now, init_time) { Padrino.cache.set(@test_key, 'test', :expires_in => 1) }
|
39
|
-
Time.stub(:now, init_time + 20) { assert_equal nil, Padrino.cache.get(@test_key) }
|
40
|
-
end
|
41
|
-
|
42
|
-
it "be able to cache forever" do
|
43
|
-
Padrino.cache.set('forever', 'cached', :expires_in => -1)
|
44
|
-
2.times { |i| assert_equal 'cached', Padrino.cache.get('forever') }
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'delete a value' do
|
48
|
-
Padrino.cache.set(@test_key, 'test')
|
49
|
-
assert_equal 'test', Padrino.cache.get(@test_key)
|
50
|
-
Padrino.cache.delete(@test_key)
|
51
|
-
assert_equal nil, Padrino.cache.get(@test_key)
|
52
|
-
end
|
53
|
-
end
|