padrino-cache 0.10.7 → 0.11.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fc390f391ec3d14847dae34892ad6b62846977f7
4
+ data.tar.gz: 56a885075563ef0c766efc4a81bd2c9f227aad5b
5
+ SHA512:
6
+ metadata.gz: c1049110996b6d6b3445f4abaec8074f1ef57a065678fe048193c5432663f0daaf2a58b5ed44484ee5311fa6001f41f03d4554a48eef330b86270fdf1a80f43f
7
+ data.tar.gz: 5f8167280f784b6906f7493af75c863ce0b976db69e95b44f1245c91e282ecff2c775102145300e560c6da4690366a8beac63b612e4e44e391ca2280e6204466
@@ -5,8 +5,8 @@ module Padrino
5
5
 
6
6
  # @api private
7
7
  def expire(*key)
8
- if key.size == 1 and key.first.is_a?(String)
9
- settings.cache.delete(key)
8
+ if key.size == 1 and (key.first.is_a?(String) or key.first.is_a?(Symbol))
9
+ settings.cache.delete(key.first)
10
10
  else
11
11
  settings.cache.delete(self.class.url(*key))
12
12
  end
@@ -95,20 +95,17 @@ module Padrino
95
95
  logger.debug "GET Cache", began_at, @route.cache_key || env['PATH_INFO'] if defined?(logger) && value
96
96
 
97
97
  if value
98
- content_type(value[:content_type]) if value[:content_type]
99
- halt 200, value[:response_buffer] if value[:response_buffer]
98
+ # content_type(value[:content_type]) if value[:content_type]
99
+ halt 200, value
100
100
  end
101
101
  end
102
102
  end
103
103
 
104
104
  route.after_filters do
105
- if settings.caching?
105
+ if settings.caching? && @_response_buffer.kind_of?(String)
106
106
  began_at = Time.now
107
107
 
108
- content = {
109
- :response_buffer => @_response_buffer,
110
- :content_type => @_content_type
111
- }
108
+ content = @_response_buffer
112
109
 
113
110
  if @_last_expires_in
114
111
  settings.cache.set(@route.cache_key || env['PATH_INFO'], content, :expires_in => @_last_expires_in)
@@ -116,6 +113,7 @@ module Padrino
116
113
  else
117
114
  settings.cache.set(@route.cache_key || env['PATH_INFO'], content)
118
115
  end
116
+
119
117
  logger.debug "SET Cache", began_at, @route.cache_key || env['PATH_INFO'] if defined?(logger)
120
118
  end
121
119
  end
@@ -0,0 +1,37 @@
1
+ module Padrino
2
+ module Cache
3
+
4
+ ##
5
+ # Defines a padrino parser for our cache store.
6
+ #
7
+ module Parser
8
+ ##
9
+ # With Parser::Plain we will store
10
+ # text and object in a text format.
11
+ #
12
+ module Plain
13
+ def self.decode(code)
14
+ code.to_s
15
+ end
16
+
17
+ def self.encode(code)
18
+ code.to_s
19
+ end
20
+ end
21
+
22
+ ##
23
+ # With Parser::Marshal we will store
24
+ # text and object in a marshalled format.
25
+ #
26
+ module Marshal
27
+ def self.decode(code)
28
+ ::Marshal.load(code.to_s)
29
+ end
30
+
31
+ def self.encode(code)
32
+ ::Marshal.dump(code)
33
+ end
34
+ end
35
+ end # Parser
36
+ end # Cache
37
+ end # Padrino
@@ -0,0 +1,63 @@
1
+ module Padrino
2
+ module Cache
3
+ module Store
4
+ ##
5
+ # Abstract Cache Store
6
+ #
7
+ class Base
8
+
9
+ ##
10
+ # Get the cache parser strategy
11
+ #
12
+ # By default is plain, otherwise you can set **Marshal** or write your own.
13
+ #
14
+ def parser
15
+ @_parser
16
+ end
17
+
18
+ ##
19
+ # Set the caching parser strategy
20
+ #
21
+ # @param value
22
+ # Module of Padrino::Cache::Parser or any that respond to encode/decode
23
+ #
24
+ # @example
25
+ # Padrino.cache.parser = :plain
26
+ # Padrino.cache.parser = :marshal
27
+ # # shortcuts for:
28
+ # Padrino.cache.parser = Padrino::Cache::Parser::Plain
29
+ # Padrino.cache.parser = Padrino::Cache::Parser::Marshal
30
+ #
31
+ # You can easily write your own:
32
+ #
33
+ # @example
34
+ # require 'oj'
35
+ # module FastJSONParser
36
+ # def self.encode(value)
37
+ # OJ.dump(value)
38
+ # end
39
+ #
40
+ # def self.decode(value)
41
+ # Oj.load(value)
42
+ # end
43
+ # end
44
+ #
45
+ # Padrino.cache_parser = FastJSONParser
46
+ #
47
+ def parser=(mod)
48
+ mod = Padrino::Cache::Parser.const_get(mod.to_s.camelize) unless mod.is_a?(Module)
49
+ raise "#{mod} should respond to encode" unless mod.respond_to?(:encode)
50
+ raise "#{mod} should respond to decode" unless mod.respond_to?(:decode)
51
+ @_parser=mod
52
+ end
53
+
54
+ # @private
55
+ def initialize(options={})
56
+ self.parser = options[:parser] || :plain
57
+ end
58
+
59
+ end # Base
60
+ end # Store
61
+ end # Cache
62
+ end # Padrino
63
+
@@ -4,7 +4,7 @@ module Padrino
4
4
  ##
5
5
  # File based Cache Store
6
6
  #
7
- class File
7
+ class File < Base
8
8
  ##
9
9
  # Initialize File store with File root
10
10
  #
@@ -15,10 +15,13 @@ module Padrino
15
15
  # Padrino.cache = Padrino::Cache::Store::File.new("path/to")
16
16
  # # or from your app
17
17
  # set :cache, Padrino::Cache::Store::File.new("path/to")
18
+ # # you can provide a marshal parser (to store ruby objects)
19
+ # set :cache, Padrino::Cache::Store::File.new("path/to", :parser => :marshal)
18
20
  #
19
21
  # @api public
20
- def initialize(root)
22
+ def initialize(root, options={})
21
23
  @root = root
24
+ super(options)
22
25
  end
23
26
 
24
27
  ##
@@ -40,7 +43,7 @@ module Padrino
40
43
  expires_in, body = contents.split("\n", 2)
41
44
  expires_in = expires_in.to_i
42
45
  if expires_in == -1 or Time.new.to_i < expires_in
43
- Marshal.load(body) if body
46
+ parser.decode(body) if body
44
47
  else # expire the key
45
48
  delete(key)
46
49
  nil
@@ -72,8 +75,8 @@ module Padrino
72
75
  else
73
76
  expires_in = -1
74
77
  end
75
- value = Marshal.dump(value) if value
76
- ::File.open(path_for_key(key), 'w') { |f| f << expires_in.to_s << "\n" << value } if value
78
+ value = parser.encode(value) if value
79
+ ::File.open(path_for_key(key), 'wb') { |f| f << expires_in.to_s << "\n" << value } if value
77
80
  end
78
81
 
79
82
  ##
@@ -4,7 +4,7 @@ module Padrino
4
4
  ##
5
5
  # Memcache Cache Store
6
6
  #
7
- class Memcache
7
+ class Memcache < Base
8
8
  ##
9
9
  # Initialize Memcache store with client connection.
10
10
  #
@@ -19,10 +19,9 @@ module Padrino
19
19
  # set :cache, Padrino::Cache::Store::Memcache.new(::Memcached.new('127.0.0.1:11211', :exception_retry_limit => 1))
20
20
  #
21
21
  # @api public
22
- def initialize(client)
22
+ def initialize(client, options={})
23
23
  @backend = client
24
- rescue
25
- raise
24
+ super(options)
26
25
  end
27
26
 
28
27
  ##
@@ -4,7 +4,7 @@ module Padrino
4
4
  ##
5
5
  # Memory Cache Store
6
6
  #
7
- class Memory
7
+ class Memory < Base
8
8
  ##
9
9
  # Initialize Memory Store with memory size
10
10
  #
@@ -17,8 +17,9 @@ module Padrino
17
17
  # set :cache, Padrino::Cache::Store::Memory.new(10000)
18
18
  #
19
19
  # @api public
20
- def initialize(size = 5000)
20
+ def initialize(size = 5000, options={})
21
21
  @size, @entries, @index = size, [], {}
22
+ super(options)
22
23
  end
23
24
 
24
25
  ##
@@ -4,7 +4,7 @@ module Padrino
4
4
  ##
5
5
  # MongoDB Cache Store
6
6
  #
7
- class Mongo
7
+ class Mongo < Base
8
8
  ##
9
9
  # Initialize Mongo store with client connection and optional username and password.
10
10
  #
@@ -17,21 +17,24 @@ module Padrino
17
17
  # Padrino.cache = Padrino::Cache::Store::Mongo.new(::Mongo::Connection.new('127.0.0.1', 27017).db('padrino'), :username => 'username', :password => 'password', :size => 64, :max => 100, :collection => 'cache')
18
18
  # # or from your app
19
19
  # set :cache, Padrino::Cache::Store::Mongo.new(::Mongo::Connection.new('127.0.0.1', 27017).db('padrino'), :username => 'username', :password => 'password', :size => 64, :max => 100, :collection => 'cache')
20
+ # # you can provide a marshal parser (to store ruby objects)
21
+ # set :cache, Padrino::Cache::Store::Mongo.new(::Mongo::Connection.new('127.0.0.1', 27017).db('padrino'), :parser => :marshal)
20
22
  #
21
23
  # @api public
22
- def initialize(client, opts={})
24
+ def initialize(client, options={})
23
25
  @client = client
24
26
  @options = {
25
27
  :capped => true,
26
28
  :collection => 'cache',
27
29
  :size => 64,
28
30
  :max => 100
29
- }.merge(opts)
31
+ }.merge(options)
30
32
 
31
33
  if @options[:username] && @options[:password]
32
34
  @client.authenticate(@options[:username], @options[:password], true)
33
35
  end
34
36
  @backend = get_collection
37
+ super(options)
35
38
  end
36
39
 
37
40
  ##
@@ -47,7 +50,7 @@ module Padrino
47
50
  def get(key)
48
51
  doc = @backend.find_one(:_id => key, :expires_in => {'$gt' => Time.now.utc})
49
52
  return nil if doc.nil?
50
- Marshal.load(doc['value'].to_s) if doc['value'].present?
53
+ parser.decode(doc['value'].to_s)
51
54
  end
52
55
 
53
56
  ##
@@ -66,7 +69,7 @@ module Padrino
66
69
  # @api public
67
70
  def set(key, value, opts = nil)
68
71
  key = key.to_s
69
- value = BSON::Binary.new(Marshal.dump(value)) if value
72
+ value = BSON::Binary.new(parser.encode(value)) if value
70
73
  if opts && opts[:expires_in]
71
74
  expires_in = opts[:expires_in].to_i
72
75
  expires_in = Time.now.utc + expires_in if expires_in < EXPIRES_EDGE
@@ -76,7 +79,8 @@ module Padrino
76
79
  @backend.update(
77
80
  {:_id => key},
78
81
  {:_id => key, :value => value, :expires_in => expires_in },
79
- {:upsert => true})
82
+ {:upsert => true}
83
+ )
80
84
  end
81
85
 
82
86
  ##
@@ -4,7 +4,7 @@ module Padrino
4
4
  ##
5
5
  # Redis Cache Store
6
6
  #
7
- class Redis
7
+ class Redis < Base
8
8
  ##
9
9
  # Initialize Redis store with client connection.
10
10
  #
@@ -15,10 +15,13 @@ module Padrino
15
15
  # Padrino.cache = Padrino::Cache::Store::Redis.new(::Redis.new(:host => '127.0.0.1', :port => 6379, :db => 0))
16
16
  # # or from your app
17
17
  # set :cache, Padrino::Cache::Store::Redis.new(::Redis.new(:host => '127.0.0.1', :port => 6379, :db => 0))
18
+ # # you can provide a marshal parser (to store ruby objects)
19
+ # set :cache, Padrino::Cache::Store::Redis.new(::Redis.new(:host => '127.0.0.1', :port => 6379, :db => 0), :parser => :marshal)
18
20
  #
19
21
  # @api public
20
- def initialize(client)
22
+ def initialize(client, options={})
21
23
  @backend = client
24
+ super(options)
22
25
  end
23
26
 
24
27
  ##
@@ -34,7 +37,8 @@ module Padrino
34
37
  # @api public
35
38
  def get(key)
36
39
  code = @backend.get(key)
37
- Marshal.load(code) if code.present?
40
+ return nil unless code
41
+ parser.decode(code)
38
42
  end
39
43
 
40
44
  ##
@@ -52,7 +56,7 @@ module Padrino
52
56
  #
53
57
  # @api public
54
58
  def set(key, value, opts = nil)
55
- value = Marshal.dump(value) if value
59
+ value = parser.encode(value)
56
60
  if opts && opts[:expires_in]
57
61
  expires_in = opts[:expires_in].to_i
58
62
  expires_in = expires_in if expires_in < EXPIRES_EDGE
@@ -7,6 +7,7 @@ module Padrino
7
7
  # The defined duration for the expiration edge.
8
8
  EXPIRES_EDGE = 86400
9
9
 
10
+ autoload :Base, 'padrino-cache/store/base'
10
11
  autoload :File, 'padrino-cache/store/file'
11
12
  autoload :Memcache, 'padrino-cache/store/memcache'
12
13
  autoload :Memory, 'padrino-cache/store/memory'
data/lib/padrino-cache.rb CHANGED
@@ -43,7 +43,7 @@ module Padrino
43
43
  #
44
44
  # @api public
45
45
  def cache=(value)
46
- @_cache = value
46
+ @_cache= value
47
47
  end
48
48
  end # self
49
49
 
@@ -54,7 +54,8 @@ module Padrino
54
54
  # of your choosing. Several common caching stores are supported out of the box.
55
55
  #
56
56
  module Cache
57
- autoload :Store, 'padrino-cache/store'
57
+ autoload :Store, 'padrino-cache/store'
58
+ autoload :Parser, 'padrino-cache/parser'
58
59
 
59
60
  class << self
60
61
  ##
@@ -101,5 +102,7 @@ module Padrino
101
102
  Padrino::Cache::Helpers::Page.padrino_route_added(route, verb, path, args, options, block)
102
103
  end
103
104
  end
105
+
106
+ Padrino.cache = Store::Memory.new(50)
104
107
  end # Cache
105
108
  end # Padrino
@@ -23,4 +23,5 @@ Gem::Specification.new do |s|
23
23
  s.rdoc_options = ["--charset=UTF-8"]
24
24
 
25
25
  s.add_runtime_dependency("padrino-core", Padrino.version)
26
+ s.add_runtime_dependency("padrino-helpers", Padrino.version)
26
27
  end
data/test/shared.rb ADDED
@@ -0,0 +1,37 @@
1
+ class Foo
2
+ def bar; "bar"; end
3
+ end
4
+
5
+ should "return nil trying to get a value that doesn't exist" do
6
+ assert_equal nil, Padrino.cache.get(@test_key)
7
+ end
8
+
9
+ should 'set and get an object w/marshal' do
10
+ Padrino.cache.parser = :marshal
11
+ Padrino.cache.set(@test_key, Foo.new)
12
+ assert_equal "bar", Padrino.cache.get(@test_key).bar
13
+ end
14
+
15
+ should 'set and get a nil value' do
16
+ Padrino.cache.set(@test_key, nil)
17
+ assert_equal '', Padrino.cache.get(@test_key).to_s
18
+ end
19
+
20
+ should 'set and get a raw value' do
21
+ Padrino.cache.set(@test_key, 'foo')
22
+ assert_equal 'foo', Padrino.cache.get(@test_key)
23
+ end
24
+
25
+ should "set a value that expires" do
26
+ Padrino.cache.set(@test_key, 'test', :expires_in => 1)
27
+ # assert_equal 'test', Padrino.cache.get(@test_key) # Fails on race condition
28
+ sleep 2
29
+ assert_equal nil, Padrino.cache.get(@test_key)
30
+ end
31
+
32
+ should 'delete a value' do
33
+ Padrino.cache.set(@test_key, 'test')
34
+ assert_equal 'test', Padrino.cache.get(@test_key)
35
+ Padrino.cache.delete(@test_key)
36
+ assert_equal nil, Padrino.cache.get(@test_key)
37
+ end
@@ -1,10 +1,13 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/helper')
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
3
  describe "PadrinoCache" do
4
4
 
5
- def teardown
6
- tmp = File.expand_path(File.dirname(__FILE__) + "/tmp")
7
- `rm -rf #{tmp}`
5
+ before do
6
+ end
7
+
8
+ after do
9
+ tmp = File.expand_path("../tmp", __FILE__)
10
+ %x[rm -rf #{tmp}]
8
11
  end
9
12
 
10
13
  should 'cache a fragment' do
@@ -87,14 +90,14 @@ describe "PadrinoCache" do
87
90
  get "/foo"
88
91
  assert_equal 200, status
89
92
  assert_equal 'foo', body
90
- assert_equal 'foo', @app.cache.get(:foo)[:response_buffer]
93
+ assert_equal 'foo', @app.cache.get(:foo)
91
94
  get "/foo"
92
95
  assert_equal 'foo', body
93
96
 
94
97
  get "/bar"
95
98
  assert_equal 200, status
96
99
  assert_equal 'bar', body
97
- assert_equal 'bar', @app.cache.get(:bar)[:response_buffer]
100
+ assert_equal 'bar', @app.cache.get(:bar)
98
101
  get "/bar"
99
102
  assert_equal 'bar', body
100
103
  end
@@ -215,4 +218,56 @@ describe "PadrinoCache" do
215
218
  get "/foo"
216
219
  assert_equal 500, status
217
220
  end
221
+
222
+ should 'not cache integer statuses' do
223
+ mock_app do
224
+ register Padrino::Cache
225
+ enable :caching
226
+ get( '/404', :cache => true ) { not_found }
227
+ get( '/503', :cache => true ) { error 503 }
228
+ not_found { 'fancy 404' }
229
+ error( 503 ) { 'fancy 503' }
230
+ end
231
+ get '/404'
232
+ assert_equal 'fancy 404', body
233
+ assert_equal 404, status
234
+ assert_equal nil, @app.cache.get('/404')
235
+ get '/404'
236
+ assert_equal 'fancy 404', body
237
+ assert_equal 404, status
238
+ get '/503'
239
+ assert_equal 'fancy 503', body
240
+ assert_equal 503, status
241
+ assert_equal nil, @app.cache.get('/503')
242
+ get '/503'
243
+ assert_equal 'fancy 503', body
244
+ assert_equal 503, status
245
+ end
246
+
247
+ should 'cache should not hit with unique params' do
248
+ call_count = 0
249
+ mock_app do
250
+ register Padrino::Cache
251
+ enable :caching
252
+ before do
253
+ param = params[:test] || 'none'
254
+ cache_key "foo?#{param}"
255
+ end
256
+ get '/foo/:test', :cache => true do
257
+ param = params[:test] || 'none'
258
+ call_count += 1
259
+ "foo?#{param}"
260
+ end
261
+ end
262
+
263
+ get '/foo/none'
264
+ get '/foo/none'
265
+ assert_equal 200, status
266
+ assert_equal 'foo?none', body
267
+ assert_equal 1, call_count
268
+
269
+ get '/foo/yes'
270
+ assert_equal 'foo?yes', body
271
+ assert_equal 2, call_count
272
+ end
218
273
  end
data/test/test_stores.rb CHANGED
@@ -1,67 +1,32 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/helper')
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
- class Foo
4
- def bar; "bar"; end
5
- end
6
-
7
- COMMON_TESTS = <<-HERE_DOC
8
- should "return nil trying to get a value that doesn't exist" do
9
- assert_equal nil, Padrino.cache.get(@test_key)
10
- end
11
-
12
- should 'set and get an object' do
13
- Padrino.cache.set(@test_key, Foo.new)
14
- assert_equal "bar", Padrino.cache.get(@test_key).bar
15
- end
16
-
17
- should 'set and get a nil value' do
18
- Padrino.cache.set(@test_key, nil)
19
- assert_equal nil, Padrino.cache.get(@test_key)
20
- end
21
-
22
- should 'set and get a raw value' do
23
- Padrino.cache.set(@test_key, 'foo')
24
- assert_equal 'foo', Padrino.cache.get(@test_key)
25
- end
26
-
27
- should "set a value that expires" do
28
- Padrino.cache.set(@test_key, 'test', :expires_in => 1)
29
- # assert_equal 'test', Padrino.cache.get(@test_key) # Fails on race condition
30
- sleep 2
31
- assert_equal nil, Padrino.cache.get(@test_key)
32
- end
33
-
34
- should 'delete a value' do
35
- Padrino.cache.set(@test_key, 'test')
36
- assert_equal 'test', Padrino.cache.get(@test_key)
37
- Padrino.cache.delete(@test_key)
38
- assert_equal nil, Padrino.cache.get(@test_key)
39
- end
40
- HERE_DOC
3
+ Shared = File.read File.expand_path('../shared.rb', __FILE__)
41
4
 
42
5
  begin
43
- require 'memcache'
6
+ require 'memcached'
44
7
  # we're just going to assume memcached is running on the default port
45
- Padrino::Cache::Store::Memcache.new(::MemCache.new('127.0.0.1:11211', :exception_retry_limit => 1)).set('ping','alive')
46
-
8
+ Padrino::Cache::Store::Memcache.new(::Memcached.new('127.0.0.1:11211', :exception_retry_limit => 1)).set('ping','alive')
9
+ rescue LoadError
10
+ warn "Skipping memcache with memcached library tests"
11
+ rescue Memcached::SystemError
12
+ warn "Skipping memcache with memcached server tests"
13
+ else
47
14
  describe "MemcacheStore" do
48
15
  def setup
49
- Padrino.cache = Padrino::Cache::Store::Memcache.new(::MemCache.new('127.0.0.1:11211', :exception_retry_limit => 1))
16
+ Padrino.cache = Padrino::Cache::Store::Memcache.new(::Memcached.new('127.0.0.1:11211', :exception_retry_limit => 1))
50
17
  Padrino.cache.flush
18
+ @test_key = "val_#{Time.now.to_i}"
51
19
  end
52
20
 
53
21
  def teardown
54
22
  Padrino.cache.flush
55
23
  end
56
24
 
57
- eval COMMON_TESTS
25
+ eval Shared
58
26
  end
59
- rescue LoadError
60
- warn "Skipping memcache with memcached library tests"
61
27
  end
62
28
 
63
29
  begin
64
- raise LoadError, 'Not working on Travis ...'
65
30
  require 'dalli'
66
31
  # we're just going to assume memcached is running on the default port
67
32
  Padrino::Cache::Store::Memcache.new(::Dalli::Client.new('127.0.0.1:11211', :exception_retry_limit => 1).set('ping','alive'))
@@ -77,7 +42,7 @@ begin
77
42
  Padrino.cache.flush
78
43
  end
79
44
 
80
- eval COMMON_TESTS
45
+ eval Shared
81
46
  end
82
47
  rescue LoadError
83
48
  warn "Skipping memcache with dalli library tests"
@@ -86,6 +51,11 @@ end
86
51
  begin
87
52
  require 'redis'
88
53
  Padrino::Cache::Store::Redis.new(::Redis.new(:host => '127.0.0.1', :port => 6379, :db => 0).set('ping','alive'))
54
+ rescue LoadError
55
+ warn "Skipping redis with redis library tests"
56
+ rescue Redis::CannotConnectError
57
+ warn "Skipping redis with redis server tests"
58
+ else
89
59
  describe "RedisStore" do
90
60
  def setup
91
61
  Padrino.cache = Padrino::Cache::Store::Redis.new(::Redis.new(:host => '127.0.0.1', :port => 6379, :db => 0))
@@ -104,15 +74,18 @@ should 'add a value to a list' do
104
74
  end
105
75
  REDIS_TEST
106
76
 
107
- eval COMMON_TESTS
77
+ eval Shared
108
78
  end
109
- rescue LoadError
110
- warn "Skipping redis tests"
111
79
  end
112
80
 
113
81
  begin
114
82
  require 'mongo'
115
83
  Padrino::Cache::Store::Mongo.new(::Mongo::Connection.new('127.0.0.1', 27017).db('padrino-cache_test'))
84
+ rescue LoadError
85
+ warn "Skipping Mongo tests with Mongo library tests"
86
+ rescue Mongo::ConnectionFailure
87
+ warn "Skipping Mongo with server tests"
88
+ else
116
89
  describe "MongoStore" do
117
90
  def setup
118
91
  Padrino.cache = Padrino::Cache::Store::Mongo.new(::Mongo::Connection.new('127.0.0.1', 27017).db('padrino-cache_test'), {:size => 10, :collection => 'cache'})
@@ -124,10 +97,8 @@ begin
124
97
  Padrino.cache.flush
125
98
  end
126
99
 
127
- eval COMMON_TESTS
100
+ eval Shared
128
101
  end
129
- rescue LoadError
130
- warn "Skipping Mongo tests"
131
102
  end
132
103
 
133
104
  describe "FileStore" do
@@ -142,7 +113,7 @@ describe "FileStore" do
142
113
  Padrino.cache.flush
143
114
  end
144
115
 
145
- eval COMMON_TESTS
116
+ eval Shared
146
117
  end
147
118
 
148
119
  describe "InMemoryStore" do
@@ -155,7 +126,7 @@ describe "InMemoryStore" do
155
126
  Padrino.cache.flush
156
127
  end
157
128
 
158
- eval COMMON_TESTS
129
+ eval Shared
159
130
 
160
131
  should "only store 50 entries" do
161
132
  51.times { |i| Padrino.cache.set(i.to_s, i.to_s) }
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.7
5
- prerelease:
4
+ version: 0.11.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Padrino Team
@@ -12,24 +11,36 @@ authors:
12
11
  autorequire:
13
12
  bindir: bin
14
13
  cert_chain: []
15
- date: 2012-06-20 00:00:00.000000000 Z
14
+ date: 2013-03-22 00:00:00.000000000 Z
16
15
  dependencies:
17
16
  - !ruby/object:Gem::Dependency
18
17
  name: padrino-core
19
18
  requirement: !ruby/object:Gem::Requirement
20
- none: false
21
19
  requirements:
22
20
  - - '='
23
21
  - !ruby/object:Gem::Version
24
- version: 0.10.7
22
+ version: 0.11.0
25
23
  type: :runtime
26
24
  prerelease: false
27
25
  version_requirements: !ruby/object:Gem::Requirement
28
- none: false
29
26
  requirements:
30
27
  - - '='
31
28
  - !ruby/object:Gem::Version
32
- version: 0.10.7
29
+ version: 0.11.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: padrino-helpers
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - '='
35
+ - !ruby/object:Gem::Version
36
+ version: 0.11.0
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '='
42
+ - !ruby/object:Gem::Version
43
+ version: 0.11.0
33
44
  description: Caching support for memcached, page and fragment
34
45
  email: padrinorb@gmail.com
35
46
  executables: []
@@ -47,7 +58,9 @@ files:
47
58
  - lib/padrino-cache/helpers/cache_store.rb
48
59
  - lib/padrino-cache/helpers/fragment.rb
49
60
  - lib/padrino-cache/helpers/page.rb
61
+ - lib/padrino-cache/parser.rb
50
62
  - lib/padrino-cache/store.rb
63
+ - lib/padrino-cache/store/base.rb
51
64
  - lib/padrino-cache/store/file.rb
52
65
  - lib/padrino-cache/store/memcache.rb
53
66
  - lib/padrino-cache/store/memory.rb
@@ -55,35 +68,36 @@ files:
55
68
  - lib/padrino-cache/store/redis.rb
56
69
  - padrino-cache.gemspec
57
70
  - test/helper.rb
71
+ - test/shared.rb
58
72
  - test/test_padrino_cache.rb
59
73
  - test/test_stores.rb
60
74
  homepage: http://www.padrinorb.com
61
75
  licenses: []
76
+ metadata: {}
62
77
  post_install_message:
63
78
  rdoc_options:
64
79
  - --charset=UTF-8
65
80
  require_paths:
66
81
  - lib
67
82
  required_ruby_version: !ruby/object:Gem::Requirement
68
- none: false
69
83
  requirements:
70
- - - ! '>='
84
+ - - '>='
71
85
  - !ruby/object:Gem::Version
72
86
  version: '0'
73
87
  required_rubygems_version: !ruby/object:Gem::Requirement
74
- none: false
75
88
  requirements:
76
- - - ! '>='
89
+ - - '>='
77
90
  - !ruby/object:Gem::Version
78
91
  version: 1.3.6
79
92
  requirements: []
80
93
  rubyforge_project: padrino-cache
81
- rubygems_version: 1.8.21
94
+ rubygems_version: 2.0.3
82
95
  signing_key:
83
- specification_version: 3
96
+ specification_version: 4
84
97
  summary: Page and fragment caching for Padrino
85
98
  test_files:
86
99
  - test/helper.rb
100
+ - test/shared.rb
87
101
  - test/test_padrino_cache.rb
88
102
  - test/test_stores.rb
89
103
  has_rdoc: