padrino-cache 0.11.3 → 0.11.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 374334fdc24a2ded02fce9d03b21176bcb9692b8
4
+ data.tar.gz: d6d07f4a86e8d5ecbd0fc53654dc328b9240d166
5
+ SHA512:
6
+ metadata.gz: 9d550329256cbf42946e0205fa4edd5670ee01873d9291f0ba5dff6ae77969f712152d3247a2bfdd5e1ce725f94395741c34ef358a08ae61752d8381c806da75
7
+ data.tar.gz: e9c536170da6ef7e61bcbaf77c6b6acebb13844a7713ab2a4f54652fa38f9c06bcc2df96f02477b31dac6e8225844d8ede8ac754905644483499da18f6628187
data/README.rdoc CHANGED
@@ -336,4 +336,4 @@ Page-level expiration works exactly like the example above--by using
336
336
 
337
337
  == Copyright
338
338
 
339
- Copyright (c) 2011 Padrino. See LICENSE for details.
339
+ Copyright (c) 2011-2013 Padrino. See LICENSE for details.
data/lib/padrino-cache.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'fileutils'
1
+ require 'fileutils' unless defined?(FileUtils)
2
2
  require 'padrino-core'
3
3
  require 'padrino-helpers'
4
4
  FileSet.glob_require('padrino-cache/{helpers}/*.rb', __FILE__)
@@ -6,7 +6,7 @@ FileSet.glob_require('padrino-cache/{helpers}/*.rb', __FILE__)
6
6
  module Padrino
7
7
  class << self
8
8
  ##
9
- # Returns the caching engine
9
+ # Returns the caching engine.
10
10
  #
11
11
  # @example
12
12
  # # with: Padrino.cache = Padrino::Cache::Store::File.new(/my/cache/path)
@@ -15,13 +15,12 @@ module Padrino
15
15
  # Padrino.cache.delete('val')
16
16
  # Padrino.cache.flush
17
17
  #
18
- # @api public
19
18
  def cache
20
19
  @_cache
21
20
  end
22
21
 
23
22
  ##
24
- # Set the caching engine
23
+ # Set the caching engine.
25
24
  #
26
25
  # @param value
27
26
  # Instance of Padrino::Cache::Store
@@ -41,11 +40,10 @@ module Padrino
41
40
  # Padrino.cache.delete('val')
42
41
  # Padrino.cache.flush
43
42
  #
44
- # @api public
45
43
  def cache=(value)
46
44
  @_cache= value
47
45
  end
48
- end # self
46
+ end
49
47
 
50
48
  ##
51
49
  # This component enables caching of an application's response contents on
@@ -71,7 +69,7 @@ module Padrino
71
69
  #
72
70
  # set :cache, Padrino::Cache::Store::File.new(File.join(app.root, 'tmp', 'cache'))
73
71
  #
74
- # However, you can also change the file store easiily in your app.rb:
72
+ # However, you can also change the file store easily in your app.rb:
75
73
  #
76
74
  # set :cache, Padrino::Cache::Store::Memcache.new(::Memcached.new('127.0.0.1:11211', :exception_retry_limit => 1))
77
75
  # set :cache, Padrino::Cache::Store::Memcache.new(::Dalli::Client.new('127.0.0.1:11211', :exception_retry_limit => 1))
@@ -87,7 +85,6 @@ module Padrino
87
85
  # MyApp.cache.delete('val')
88
86
  # MyApp.cache.flush
89
87
  #
90
- # @api public
91
88
  def registered(app)
92
89
  app.helpers Padrino::Cache::Helpers::CacheStore
93
90
  app.helpers Padrino::Cache::Helpers::Fragment
@@ -97,12 +94,11 @@ module Padrino
97
94
  end
98
95
  alias :included :registered
99
96
 
100
- # @private
101
- def padrino_route_added(route, verb, path, args, options, block) # @private
97
+ def padrino_route_added(route, verb, path, args, options, block)
102
98
  Padrino::Cache::Helpers::Page.padrino_route_added(route, verb, path, args, options, block)
103
99
  end
104
100
  end
105
101
 
106
102
  Padrino.cache = Store::Memory.new(50)
107
- end # Cache
108
- end # Padrino
103
+ end
104
+ end
@@ -1,9 +1,7 @@
1
1
  module Padrino
2
2
  module Cache
3
3
  module Helpers
4
- module CacheStore # @private
5
-
6
- # @api private
4
+ module CacheStore
7
5
  def expire(*key)
8
6
  if key.size == 1 and (key.first.is_a?(String) or key.first.is_a?(Symbol))
9
7
  settings.cache.delete(key.first)
@@ -11,7 +9,7 @@ module Padrino
11
9
  settings.cache.delete(self.class.url(*key))
12
10
  end
13
11
  end
14
- end # CacheStore
15
- end # Helpers
16
- end # Cache
17
- end # Padrino
12
+ end
13
+ end
14
+ end
15
+ end
@@ -8,10 +8,10 @@ module Padrino
8
8
  #
9
9
  # Possible uses for fragment caching might include:
10
10
  #
11
- # * a 'feed' of some items on a page
12
- # * output fetched (by proxy) from an API on a third-party site
13
- # * parts of your page which are largely static/do not need re-rendering every request
14
- # * any output which is expensive to render
11
+ # - a 'feed' of some items on a page
12
+ # - output fetched (by proxy) from an API on a third-party site
13
+ # - parts of your page which are largely static/do not need re-rendering every request
14
+ # - any output which is expensive to render
15
15
  #
16
16
  module Fragment
17
17
  include Padrino::Helpers::OutputHelpers
@@ -41,13 +41,12 @@ module Padrino
41
41
  # render 'partials/feedcontent'
42
42
  # end
43
43
  #
44
- # # Below outputs @feed somewhere in its markup
44
+ # # Below outputs @feed somewhere in its markup.
45
45
  # render 'feeds/show'
46
46
  # end
47
47
  # end
48
48
  # end
49
49
  #
50
- # @api public
51
50
  def cache(key, opts = nil, &block)
52
51
  if settings.caching?
53
52
  began_at = Time.now
@@ -62,10 +61,10 @@ module Padrino
62
61
  end
63
62
  else
64
63
  value = capture_html(&block)
65
- concat_content(value)
64
+ concat_content(value)
66
65
  end
67
66
  end
68
- end # Fragment
69
- end # Helpers
70
- end # Cache
71
- end # Padrino
67
+ end
68
+ end
69
+ end
70
+ end
@@ -7,11 +7,11 @@ module Padrino
7
7
  ##
8
8
  # Page caching is easy to integrate into your application. To turn it on, simply provide the
9
9
  # <tt>:cache => true</tt> option on either a controller or one of its routes.
10
- # By default, cached content is persisted with a "file store"--that is, in a
10
+ # By default, cached content is persisted with a "file store" --that is, in a
11
11
  # subdirectory of your application root.
12
12
  #
13
13
  # @example
14
- # # Setting content expiry time
14
+ # # Setting content expiry time.
15
15
  # class CachedApp < Padrino::Application
16
16
  # enable :caching # turns on caching mechanism
17
17
  #
@@ -20,7 +20,7 @@ module Padrino
20
20
  #
21
21
  # get '/entries' do
22
22
  # # expires_in 15 => can also be defined inside a single route
23
- # 'just broke up eating twinkies lol'
23
+ # 'Just broke up eating twinkies, lol'
24
24
  # end
25
25
  #
26
26
  # get '/post/:id' do
@@ -55,11 +55,10 @@ module Padrino
55
55
  #
56
56
  # get '/entries' do
57
57
  # # expires_in 15 => can also be defined inside a single route
58
- # 'just broke up eating twinkies lol'
58
+ # 'Just broke up eating twinkies, lol'
59
59
  # end
60
60
  # end
61
61
  #
62
- # @api public
63
62
  def expires_in(time)
64
63
  @route.cache_expires_in = time if @route
65
64
  @_last_expires_in = time
@@ -85,18 +84,16 @@ module Padrino
85
84
  # @example
86
85
  # get '/foo', :cache => true do
87
86
  # cache_key { param[:id] }
88
- # "my id is #{param[:id}"
87
+ # "My id is #{param[:id}"
89
88
  # end
90
89
  # end
91
90
  #
92
- # @api public
93
91
  def cache_key(name = nil, &block)
94
92
  raise "Can not provide both cache_key and a block" if name && block
95
93
  @route.cache_key = block_given? ? block : name
96
94
  end
97
95
 
98
- # @private
99
- def self.padrino_route_added(route, verb, path, args, options, block) # @private
96
+ def self.padrino_route_added(route, verb, path, args, options, block)
100
97
  if route.cache and %w(GET HEAD).include?(verb)
101
98
  route.before_filters do
102
99
  if settings.caching?
@@ -106,7 +103,6 @@ module Padrino
106
103
  logger.debug "GET Cache", began_at, @route.cache_key || env['PATH_INFO'] if defined?(logger) && value
107
104
 
108
105
  if value
109
- # content_type(value[:content_type]) if value[:content_type]
110
106
  halt 200, value
111
107
  end
112
108
  end
@@ -132,13 +128,12 @@ module Padrino
132
128
 
133
129
  private
134
130
  ##
135
- # Resolve the cache_key when it's a block in the correct context
136
- #@api private
131
+ # Resolve the cache_key when it's a block in the correct context.
132
+ #
137
133
  def resolve_cache_key
138
134
  @route.cache_key.is_a?(Proc) ? instance_eval(&@route.cache_key) : @route.cache_key
139
135
  end
140
-
141
- end # Page
142
- end # Helpers
143
- end # Cache
144
- end # Padrino
136
+ end
137
+ end
138
+ end
139
+ end
@@ -1,6 +1,5 @@
1
1
  module Padrino
2
2
  module Cache
3
-
4
3
  ##
5
4
  # Defines a padrino parser for our cache store.
6
5
  #
@@ -21,7 +20,7 @@ module Padrino
21
20
 
22
21
  ##
23
22
  # With Parser::Marshal we will store
24
- # text and object in a marshalled format.
23
+ # text and object in a marshaled format.
25
24
  #
26
25
  module Marshal
27
26
  def self.decode(code)
@@ -32,6 +31,6 @@ module Padrino
32
31
  ::Marshal.dump(code)
33
32
  end
34
33
  end
35
- end # Parser
36
- end # Cache
37
- end # Padrino
34
+ end
35
+ end
36
+ end
@@ -13,6 +13,6 @@ module Padrino
13
13
  autoload :Memory, 'padrino-cache/store/memory'
14
14
  autoload :Redis, 'padrino-cache/store/redis'
15
15
  autoload :Mongo, 'padrino-cache/store/mongo'
16
- end # Store
17
- end # Cache
18
- end # Padrino
16
+ end
17
+ end
18
+ end
@@ -5,9 +5,8 @@ module Padrino
5
5
  # Abstract Cache Store
6
6
  #
7
7
  class Base
8
-
9
8
  ##
10
- # Get the cache parser strategy
9
+ # Get the cache parser strategy.
11
10
  #
12
11
  # By default is plain, otherwise you can set **Marshal** or write your own.
13
12
  #
@@ -16,15 +15,16 @@ module Padrino
16
15
  end
17
16
 
18
17
  ##
19
- # Set the caching parser strategy
18
+ # Set the caching parser strategy.
20
19
  #
21
20
  # @param value
22
- # Module of Padrino::Cache::Parser or any that respond to encode/decode
21
+ # Module of Padrino::Cache::Parser or any that respond to encode/decode.
23
22
  #
24
23
  # @example
24
+ # # shorter version:
25
25
  # Padrino.cache.parser = :plain
26
26
  # Padrino.cache.parser = :marshal
27
- # # shortcuts for:
27
+ # # longer version:
28
28
  # Padrino.cache.parser = Padrino::Cache::Parser::Plain
29
29
  # Padrino.cache.parser = Padrino::Cache::Parser::Marshal
30
30
  #
@@ -34,7 +34,7 @@ module Padrino
34
34
  # require 'oj'
35
35
  # module FastJSONParser
36
36
  # def self.encode(value)
37
- # OJ.dump(value)
37
+ # Oj.dump(value)
38
38
  # end
39
39
  #
40
40
  # def self.decode(value)
@@ -51,14 +51,12 @@ module Padrino
51
51
  @_parser=mod
52
52
  end
53
53
 
54
- # @private
55
54
  def initialize(options={})
56
55
  @never = -1
57
56
  self.parser = options[:parser] || :plain
58
57
  end
59
58
 
60
59
  private
61
-
62
60
  def get_expiry( opts )
63
61
  if opts && opts[:expires_in] && opts[:expires_in] != -1
64
62
  expires_in = opts[:expires_in].to_i
@@ -72,8 +70,7 @@ module Padrino
72
70
  def now_before?( expiry )
73
71
  expiry.to_i == @never || expiry.to_i > Time.now.to_i
74
72
  end
75
- end # Base
76
- end # Store
77
- end # Cache
78
- end # Padrino
79
-
73
+ end
74
+ end
75
+ end
76
+ end
@@ -2,30 +2,29 @@ module Padrino
2
2
  module Cache
3
3
  module Store
4
4
  ##
5
- # File based Cache Store
5
+ # File based Cache Store.
6
6
  #
7
7
  class File < Base
8
8
  ##
9
- # Initialize File store with File root
9
+ # Initialize File store with File root.
10
10
  #
11
11
  # @param [String] root
12
- # path to cache file
12
+ # path to cache file.
13
13
  #
14
14
  # @example
15
15
  # Padrino.cache = Padrino::Cache::Store::File.new("path/to")
16
- # # or from your app
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)
18
+ # # You can provide a marshal parser (to store ruby objects)
19
19
  # set :cache, Padrino::Cache::Store::File.new("path/to", :parser => :marshal)
20
20
  #
21
- # @api public
22
21
  def initialize(root, options={})
23
22
  @root = root
24
23
  super(options)
25
24
  end
26
25
 
27
26
  ##
28
- # Return the a value for the given key
27
+ # Return the value for the given key.
29
28
  #
30
29
  # @param [String] key
31
30
  # cache key
@@ -34,7 +33,6 @@ module Padrino
34
33
  # # with MyApp.cache.set('records', records)
35
34
  # MyApp.cache.get('records')
36
35
  #
37
- # @api public
38
36
  def get(key)
39
37
  init
40
38
  if ::File.exist?(path_for_key(key))
@@ -53,7 +51,7 @@ module Padrino
53
51
  end
54
52
 
55
53
  ##
56
- # Set the value for a given key and optionally with an expire time
54
+ # Set the value for a given key and optionally with an expire time.
57
55
  # Default expiry time is 86400.
58
56
  #
59
57
  # @param [String] key
@@ -65,7 +63,6 @@ module Padrino
65
63
  # MyApp.cache.set('records', records)
66
64
  # MyApp.cache.set('records', records, :expires_in => 30) # => 30 seconds
67
65
  #
68
- # @api public
69
66
  def set(key, value, opts = nil)
70
67
  init
71
68
  value = parser.encode(value) if value
@@ -73,7 +70,7 @@ module Padrino
73
70
  end
74
71
 
75
72
  ##
76
- # Delete the value for a given key
73
+ # Delete the value for a given key.
77
74
  #
78
75
  # @param [String] key
79
76
  # cache key
@@ -84,37 +81,32 @@ module Padrino
84
81
  # # with: MyApp.cache.set('records', records)
85
82
  # MyApp.cache.delete('records')
86
83
  #
87
- # @api public
88
84
  def delete(key)
89
85
  init
90
86
  Array(key).each { |k| FileUtils.rm_rf(path_for_key(k)) }
91
87
  end
92
88
 
93
89
  ##
94
- # Reinitialize your cache
90
+ # Reinitialize your cache.
95
91
  #
96
92
  # @example
97
93
  # # with: MyApp.cache.set('records', records)
98
94
  # MyApp.cache.flush
99
95
  # MyApp.cache.get('records') # => nil
100
96
  #
101
- # @api public
102
97
  def flush
103
98
  FileUtils.rm_rf(@root)
104
99
  end
105
100
 
106
101
  private
107
-
108
- # @api private
109
102
  def path_for_key(key)
110
103
  ::File.join(@root, Rack::Utils.escape(key.to_s))
111
104
  end
112
105
 
113
- # @api private
114
106
  def init
115
107
  FileUtils.mkdir_p(@root) unless ::File.exist?(@root)
116
108
  end
117
- end # File
118
- end # Store
119
- end # Cache
120
- end # Padrino
109
+ end
110
+ end
111
+ end
112
+ end
@@ -18,7 +18,6 @@ module Padrino
18
18
  # set :cache, Padrino::Cache::Store::Memcache.new(::Memcached.new('127.0.0.1:11211'))
19
19
  # set :cache, Padrino::Cache::Store::Memcache.new(::Memcached.new('127.0.0.1:11211', :exception_retry_limit => 1))
20
20
  #
21
- # @api public
22
21
  def initialize(client, options={})
23
22
  @backend = client
24
23
  super(options)
@@ -26,16 +25,14 @@ module Padrino
26
25
  end
27
26
 
28
27
  ##
29
- # Return the a value for the given key
28
+ # Return the value for the given key.
30
29
  #
31
30
  # @param [String] key
32
31
  # cache key to retrieve value
33
32
  #
34
33
  # @example
35
- # # with MyApp.cache.set('records', records)
36
34
  # MyApp.cache.get('records')
37
35
  #
38
- # @api public
39
36
  def get(key)
40
37
  @backend.get(key)
41
38
  rescue Memcached::NotFound
@@ -43,7 +40,7 @@ module Padrino
43
40
  end
44
41
 
45
42
  ##
46
- # Set the value for a given key and optionally with an expire time
43
+ # Set the value for a given key and optionally with an expire time.
47
44
  # Default expiry time is 86400.
48
45
  #
49
46
  # @param [String] key
@@ -55,39 +52,34 @@ module Padrino
55
52
  # MyApp.cache.set('records', records)
56
53
  # MyApp.cache.set('records', records, :expires_in => 30) # => 30 seconds
57
54
  #
58
- # @api public
59
55
  def set(key, value, opts = nil)
60
56
  @backend.set(key, value, get_expiry(opts))
61
57
  end
62
58
 
63
59
  ##
64
- # Delete the value for a given key
60
+ # Delete the value for a given key.
65
61
  #
66
62
  # @param [String] key
67
63
  # cache key
68
64
  #
69
65
  # @example
70
- # # with: MyApp.cache.set('records', records)
71
66
  # MyApp.cache.delete('records')
72
67
  #
73
- # @api public
74
68
  def delete(key)
75
69
  @backend.delete(key)
76
70
  end
77
71
 
78
72
  ##
79
- # Reinitialize your cache
73
+ # Reinitialize your cache.
80
74
  #
81
75
  # @example
82
- # # with: MyApp.cache.set('records', records)
83
76
  # MyApp.cache.flush
84
77
  # MyApp.cache.get('records') # => nil
85
78
  #
86
- # @api public
87
79
  def flush
88
80
  @backend.respond_to?(:flush_all) ? @backend.flush_all : @backend.flush
89
81
  end
90
- end # Memcached
91
- end # Store
92
- end # Cache
93
- end # Padrino
82
+ end
83
+ end
84
+ end
85
+ end
@@ -6,33 +6,30 @@ module Padrino
6
6
  #
7
7
  class Memory < Base
8
8
  ##
9
- # Initialize Memory Store with memory size
9
+ # Initialize Memory Store with memory size.
10
10
  #
11
11
  # @param [Integer] size
12
- # Size of memory cache
12
+ # Size of memory cache.
13
13
  #
14
14
  # @example
15
15
  # Padrino.cache = Padrino::Cache::Store::Memory.new(10000)
16
16
  # # or from your app
17
17
  # set :cache, Padrino::Cache::Store::Memory.new(10000)
18
18
  #
19
- # @api public
20
19
  def initialize(size = 5000, options={})
21
20
  @size, @entries, @index = size, [], {}
22
21
  super(options)
23
22
  end
24
23
 
25
24
  ##
26
- # Return the a value for the given key
25
+ # Return the value for the given key.
27
26
  #
28
27
  # @param [String] key
29
28
  # cache key to retrieve value
30
29
  #
31
30
  # @example
32
- # # with MyApp.cache.set('records', records)
33
31
  # MyApp.cache.get('records')
34
32
  #
35
- # @api public
36
33
  def get(key)
37
34
  if @index.key?(key) and value = @index[key]
38
35
  expiry, body = value
@@ -60,7 +57,6 @@ module Padrino
60
57
  # MyApp.cache.set('records', records)
61
58
  # MyApp.cache.set('records', records, :expires_in => 30) # => 30 seconds
62
59
  #
63
- # @api public
64
60
  def set(key, value, opts = nil)
65
61
  delete(key)
66
62
  @entries.push(key)
@@ -71,33 +67,29 @@ module Padrino
71
67
  end
72
68
 
73
69
  ##
74
- # Delete the value for a given key
70
+ # Delete the value for a given key.
75
71
  #
76
72
  # @param [String] key
77
73
  # cache key
78
74
  #
79
75
  # @example
80
- # # with: MyApp.cache.set('records', records)
81
76
  # MyApp.cache.delete('records')
82
77
  #
83
- # @api public
84
78
  def delete(key)
85
79
  @index.delete(key)
86
80
  end
87
81
 
88
82
  ##
89
- # Reinitialize your cache
83
+ # Reinitialize your cache.
90
84
  #
91
85
  # @example
92
- # # with: MyApp.cache.set('records', records)
93
86
  # MyApp.cache.flush
94
87
  # MyApp.cache.get('records') # => nil
95
88
  #
96
- # @api public
97
89
  def flush
98
90
  @index = Hash.new
99
91
  end
100
- end # Memory
101
- end # Store
102
- end # Cache
103
- end # Padrino
92
+ end
93
+ end
94
+ end
95
+ end
@@ -11,7 +11,7 @@ module Padrino
11
11
  # @param client
12
12
  # Instance of Mongo connection
13
13
  # @param [Hash] opts
14
- # optiosn to pass into Mongo connection
14
+ # options to pass into Mongo connection
15
15
  #
16
16
  # @example
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')
@@ -20,7 +20,6 @@ module Padrino
20
20
  # # you can provide a marshal parser (to store ruby objects)
21
21
  # set :cache, Padrino::Cache::Store::Mongo.new(::Mongo::Connection.new('127.0.0.1', 27017).db('padrino'), :parser => :marshal)
22
22
  #
23
- # @api public
24
23
  def initialize(client, options={})
25
24
  @client = client
26
25
  @options = {
@@ -38,13 +37,12 @@ module Padrino
38
37
  end
39
38
 
40
39
  ##
41
- # Return the a value for the given key
40
+ # Return the value for the given key.
42
41
  #
43
42
  # @param [String] key
44
43
  # cache key
45
44
  #
46
45
  # @example
47
- # # with MyApp.cache.set('records', records)
48
46
  # MyApp.cache.get('records')
49
47
  #
50
48
  def get(key)
@@ -60,7 +58,7 @@ module Padrino
60
58
  end
61
59
 
62
60
  ##
63
- # Set or update the value for a given key and optionally with an expire time
61
+ # Set or update the value for a given key and optionally with an expire time.
64
62
  # Default expiry is Time.now + 86400s.
65
63
  #
66
64
  # @param [String] key
@@ -72,7 +70,6 @@ module Padrino
72
70
  # MyApp.cache.set('records', records)
73
71
  # MyApp.cache.set('records', records, :expires_in => 30) # => 30 seconds
74
72
  #
75
- # @api public
76
73
  def set(key, value, opts = nil)
77
74
  key = key.to_s
78
75
  value = BSON::Binary.new(parser.encode(value)) if value
@@ -84,16 +81,14 @@ module Padrino
84
81
  end
85
82
 
86
83
  ##
87
- # Delete the value for a given key
84
+ # Delete the value for a given key.
88
85
  #
89
86
  # @param [String] key
90
87
  # cache key
91
88
  #
92
89
  # @example
93
- # # with: MyApp.cache.set('records', records)
94
90
  # MyApp.cache.delete('records')
95
91
  #
96
- # @api public
97
92
  def delete(key)
98
93
  if not @options[:capped]
99
94
  @backend.remove({:_id => key})
@@ -104,22 +99,19 @@ module Padrino
104
99
  end
105
100
 
106
101
  ##
107
- # Reinitialize your cache
102
+ # Reinitialize your cache.
108
103
  #
109
104
  # @example
110
105
  # # with: MyApp.cache.set('records', records)
111
106
  # MyApp.cache.flush
112
107
  # MyApp.cache.get('records') # => nil
113
108
  #
114
- # @api public
115
109
  def flush
116
110
  @backend.drop
117
111
  @backend = get_collection
118
112
  end
119
113
 
120
114
  private
121
-
122
- # @api private
123
115
  def get_collection
124
116
  if @client.collection_names.include?(@options[:collection]) or !@options[:capped]
125
117
  @client.collection @options[:collection]
@@ -129,7 +121,7 @@ module Padrino
129
121
  :max => @options[:max] })
130
122
  end
131
123
  end
132
- end # Mongo
133
- end # Store
134
- end # Cache
135
- end # Padrino
124
+ end
125
+ end
126
+ end
127
+ end
@@ -9,7 +9,7 @@ module Padrino
9
9
  # Initialize Redis store with client connection.
10
10
  #
11
11
  # @param client
12
- # Instance of Redis client
12
+ # Instance of Redis client.
13
13
  #
14
14
  # @example
15
15
  # Padrino.cache = Padrino::Cache::Store::Redis.new(::Redis.new(:host => '127.0.0.1', :port => 6379, :db => 0))
@@ -18,14 +18,13 @@ module Padrino
18
18
  # # you can provide a marshal parser (to store ruby objects)
19
19
  # set :cache, Padrino::Cache::Store::Redis.new(::Redis.new(:host => '127.0.0.1', :port => 6379, :db => 0), :parser => :marshal)
20
20
  #
21
- # @api public
22
21
  def initialize(client, options={})
23
22
  @backend = client
24
23
  super(options)
25
24
  end
26
25
 
27
26
  ##
28
- # Return the a value for the given key
27
+ # Return the value for the given key.
29
28
  #
30
29
  # @param [String] key
31
30
  # cache key
@@ -34,7 +33,6 @@ module Padrino
34
33
  # # with MyApp.cache.set('records', records)
35
34
  # MyApp.cache.get('records')
36
35
  #
37
- # @api public
38
36
  def get(key)
39
37
  code = @backend.get(key)
40
38
  return nil unless code
@@ -42,7 +40,7 @@ module Padrino
42
40
  end
43
41
 
44
42
  ##
45
- # Set the value for a given key and optionally with an expire time
43
+ # Set the value for a given key and optionally with an expire time.
46
44
  # Default expiry is 86400.
47
45
  #
48
46
  # @param [String] key
@@ -54,7 +52,6 @@ module Padrino
54
52
  # MyApp.cache.set('records', records)
55
53
  # MyApp.cache.set('records', records, :expires_in => 30) # => 30 seconds
56
54
  #
57
- # @api public
58
55
  def set(key, value, opts = nil)
59
56
  value = parser.encode(value)
60
57
  if opts && opts[:expires_in] && opts[:expires_in] >= 0
@@ -66,39 +63,35 @@ module Padrino
66
63
  end
67
64
 
68
65
  ##
69
- # Delete the value for a given key
66
+ # Delete the value for a given key.
70
67
  #
71
68
  # @param [String] key
72
69
  # cache key
73
70
  #
74
71
  # @example
75
- # # with: MyApp.cache.set('records', records)
76
72
  # MyApp.cache.delete('records')
77
73
  #
78
- # @api public
79
74
  def delete(key)
80
75
  @backend.del(key)
81
76
  end
82
77
 
83
78
  ##
84
- # Reinitialize your cache
79
+ # Reinitialize your cache.
85
80
  #
86
81
  # @example
87
- # # with: MyApp.cache.set('records', records)
88
82
  # MyApp.cache.flush
89
83
  # MyApp.cache.get('records') # => nil
90
84
  #
91
- # @api public
92
85
  def flush
93
86
  @backend.flushdb
94
87
  end
95
88
 
96
89
  ##
97
- # Redis has a ton of powerful features (see: https://github.com/redis/redis-rb), which we
98
- # can't use due to how strict the cache library is. This method catches all method calls and
99
- # tries to pass them on the the redis gem.
90
+ # Redis has a ton of powerful features (see:
91
+ # https://github.com/redis/redis-rb), which we can't use due
92
+ # to how strict the cache library is. This method catches all method calls and
93
+ # tries to pass them on the redis gem.
100
94
  #
101
- # @api private
102
95
  def method_missing(name, *args, &block)
103
96
  if @backend.respond_to?(name)
104
97
  @backend.send(name, *args, &block)
@@ -106,7 +99,7 @@ module Padrino
106
99
  super
107
100
  end
108
101
  end
109
- end # Redis
110
- end # Store
111
- end # Cache
112
- end # Padrino
102
+ end
103
+ end
104
+ end
105
+ end
data/test/helper.rb CHANGED
@@ -5,7 +5,6 @@ require File.expand_path('../../../load_paths', __FILE__)
5
5
  require File.join(File.dirname(__FILE__), '..', '..', 'padrino-core', 'test', 'helper')
6
6
  require 'uuid'
7
7
  require 'padrino-cache'
8
- require 'fileutils'
9
8
 
10
9
  class MiniTest::Spec
11
10
 
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.11.3
5
- prerelease:
4
+ version: 0.11.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Padrino Team
@@ -12,40 +11,36 @@ authors:
12
11
  autorequire:
13
12
  bindir: bin
14
13
  cert_chain: []
15
- date: 2013-07-29 00:00:00.000000000 Z
14
+ date: 2013-09-24 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.11.3
22
+ version: 0.11.4
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.11.3
29
+ version: 0.11.4
33
30
  - !ruby/object:Gem::Dependency
34
31
  name: padrino-helpers
35
32
  requirement: !ruby/object:Gem::Requirement
36
- none: false
37
33
  requirements:
38
34
  - - '='
39
35
  - !ruby/object:Gem::Version
40
- version: 0.11.3
36
+ version: 0.11.4
41
37
  type: :runtime
42
38
  prerelease: false
43
39
  version_requirements: !ruby/object:Gem::Requirement
44
- none: false
45
40
  requirements:
46
41
  - - '='
47
42
  - !ruby/object:Gem::Version
48
- version: 0.11.3
43
+ version: 0.11.4
49
44
  description: Caching support for memcached, page and fragment
50
45
  email: padrinorb@gmail.com
51
46
  executables: []
@@ -83,28 +78,27 @@ files:
83
78
  - test/test_padrino_cache.rb
84
79
  homepage: http://www.padrinorb.com
85
80
  licenses: []
81
+ metadata: {}
86
82
  post_install_message:
87
83
  rdoc_options:
88
84
  - --charset=UTF-8
89
85
  require_paths:
90
86
  - lib
91
87
  required_ruby_version: !ruby/object:Gem::Requirement
92
- none: false
93
88
  requirements:
94
- - - ! '>='
89
+ - - '>='
95
90
  - !ruby/object:Gem::Version
96
91
  version: '0'
97
92
  required_rubygems_version: !ruby/object:Gem::Requirement
98
- none: false
99
93
  requirements:
100
- - - ! '>='
94
+ - - '>='
101
95
  - !ruby/object:Gem::Version
102
96
  version: 1.3.6
103
97
  requirements: []
104
98
  rubyforge_project: padrino-cache
105
- rubygems_version: 1.8.25
99
+ rubygems_version: 2.0.6
106
100
  signing_key:
107
- specification_version: 3
101
+ specification_version: 4
108
102
  summary: Page and fragment caching for Padrino
109
103
  test_files:
110
104
  - test/helper.rb