Skip to content

Commit 69aa8d2

Browse files
committed
Merge pull request padrino#1467 from minad/cache-examples
provide more examples for the instantiation of the cache stores
2 parents 9e39d9c + f476af4 commit 69aa8d2

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

padrino-cache/README.rdoc

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
This component enables caching of an application's response contents on
66
both page- and fragment-levels. Output cached in this manner is
77
persisted, until it expires or is actively expired, in a configurable store
8-
of your choosing. Several common caching stores are supported out of the box.
8+
of your choosing. Most popular key/value stores work out of the box. Take a look
9+
at the [Moneta documentation](http://rubydoc.info/gems/moneta) for a list of all supported stores.
910

1011
== Caching Quickstart
1112

@@ -214,7 +215,8 @@ Note that any other action will reference the same content if it uses the same k
214215
end
215216
end
216217

217-
The <tt>opts</tt> argument is actually passed to the underlying store. All stores included with Padrino support the <tt>:expires</tt> option out of the box.
218+
The <tt>opts</tt> argument is actually passed to the underlying store. The stores support the <tt>:expires</tt> option out of the box or
219+
are enhanced by Moneta to support it.
218220

219221
Finally, to DRY up things a bit, we might do:
220222

@@ -253,9 +255,15 @@ You can set a global caching option or a per app caching options.
253255

254256
=== Global Caching Options
255257

256-
Padrino.cache = Padrino::Cache.new(:LRUHash)
257-
Padrino.cache = Padrino::Cache.new(:Memcached)
258-
Padrino.cache = Padrino::Cache.new(:Redis)
258+
Padrino.cache = Padrino::Cache.new(:LRUHash) # Keeps cached values in memory
259+
Padrino.cache = Padrino::Cache.new(:Memcached) # Uses default server at localhost
260+
Padrino.cache = Padrino::Cache.new(:Memcached, '127.0.0.1:11211', :exception_retry_limit => 1)
261+
Padrino.cache = Padrino::Cache.new(:Memcached, :backend => memcached_or_dalli_instance)
262+
Padrino.cache = Padrino::Cache.new(:Redis) # Uses default server at localhost
263+
Padrino.cache = Padrino::Cache.new(:Redis, :host => '127.0.0.1', :port => 6379, :db => 0)
264+
Padrino.cache = Padrino::Cache.new(:Redis, :backend => redis_instance)
265+
Padrino.cache = Padrino::Cache.new(:Mongo) # Uses default server at localhost
266+
Padrino.cache = Padrino::Cache.new(:Mongo, :backend => mongo_client_instance)
259267
Padrino.cache = Padrino::Cache.new(:File, :dir => Padrino.root('tmp', app_name.to_s, 'cache')) # default choice
260268

261269
You can manage your cache from anywhere in your app:
@@ -265,6 +273,9 @@ You can manage your cache from anywhere in your app:
265273
Padrino.cache.delete('val')
266274
Padrino.cache.clear
267275

276+
The Padrino cache constructor `Padrino::Cache.new` calls `Moneta.new` to create a cache instance. Please refer to the [Moneta documentation](http://rubydoc.info/gems/moneta) if you
277+
have special requirements, for example if you want to configure the marshalling mechanism or use a more exotic backend.
278+
268279
==== Application Caching Options
269280

270281
set :cache, Padrino::Cache.new(:LRUHash)

padrino-cache/lib/padrino-cache.rb

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@ def cache
2828
# Instance of Moneta store
2929
#
3030
# @example
31-
# Padrino.cache = Padrino::Cache.new(:LRUHash)
32-
# Padrino.cache = Padrino::Cache.new(:Memcached)
33-
# Padrino.cache = Padrino::Cache.new(:Redis)
3431
# Padrino.cache = Padrino::Cache.new(:File, :dir => Padrino.root('tmp', app_name.to_s, 'cache')) # default choice
32+
# Padrino.cache = Padrino::Cache.new(:LRUHash) # Keeps cached values in memory
33+
# Padrino.cache = Padrino::Cache.new(:Memcached) # Uses default server at localhost
34+
# Padrino.cache = Padrino::Cache.new(:Memcached, '127.0.0.1:11211', :exception_retry_limit => 1)
35+
# Padrino.cache = Padrino::Cache.new(:Memcached, :backend => memcached_or_dalli_instance)
36+
# Padrino.cache = Padrino::Cache.new(:Redis) # Uses default server at localhost
37+
# Padrino.cache = Padrino::Cache.new(:Redis, :host => '127.0.0.1', :port => 6379, :db => 0)
38+
# Padrino.cache = Padrino::Cache.new(:Redis, :backend => redis_instance)
39+
# Padrino.cache = Padrino::Cache.new(:Mongo) # Uses default server at localhost
40+
# Padrino.cache = Padrino::Cache.new(:Mongo, :backend => mongo_client_instance)
3541
#
3642
# # You can manage your cache from anywhere in your app:
3743
#
@@ -68,9 +74,15 @@ class << self
6874
#
6975
# However, you can also change the file store easily in your app.rb:
7076
#
71-
# set :cache, Padrino::Cache.new(:LRUHash)
72-
# set :cache, Padrino::Cache.new(:Memcached)
73-
# set :cache, Padrino::Cache.new(:Redis)
77+
# set :cache, Padrino::Cache.new(:LRUHash) # Keeps cached values in memory
78+
# set :cache, Padrino::Cache.new(:Memcached) # Uses default server at localhost
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+
# set :cache, Padrino::Cache.new(:Redis) # Uses default server at localhost
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+
# set :cache, Padrino::Cache.new(:Mongo) # Uses default server at localhost
85+
# set :cache, Padrino::Cache.new(:Mongo, :backend => mongo_client_instance)
7486
# set :cache, Padrino::Cache.new(:File, :dir => Padrino.root('tmp', app_name.to_s, 'cache')) # default choice
7587
#
7688
# You can manage your cache from anywhere in your app:

padrino-gen/lib/padrino-gen/generators/app/app.rb.tt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ module <%= @project_name %>
1414
#
1515
# You can customize caching store engines:
1616
#
17-
# set :cache, Padrino::Cache.new(:LRUHash)
18-
# set :cache, Padrino::Cache.new(:Memcached)
19-
# set :cache, Padrino::Cache.new(:Redis)
17+
# set :cache, Padrino::Cache.new(:LRUHash) # Keeps cached values in memory
18+
# set :cache, Padrino::Cache.new(:Memcached) # Uses default server at localhost
19+
# set :cache, Padrino::Cache.new(:Memcached, '127.0.0.1:11211', :exception_retry_limit => 1)
20+
# set :cache, Padrino::Cache.new(:Memcached, :backend => memcached_or_dalli_instance)
21+
# set :cache, Padrino::Cache.new(:Redis) # Uses default server at localhost
22+
# set :cache, Padrino::Cache.new(:Redis, :host => '127.0.0.1', :port => 6379, :db => 0)
23+
# set :cache, Padrino::Cache.new(:Redis, :backend => redis_instance)
24+
# set :cache, Padrino::Cache.new(:Mongo) # Uses default server at localhost
25+
# set :cache, Padrino::Cache.new(:Mongo, :backend => mongo_client_instance)
2026
# set :cache, Padrino::Cache.new(:File, :dir => Padrino.root('tmp', app_name.to_s, 'cache')) # default choice
2127
#
2228

0 commit comments

Comments
 (0)