Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ability to register a custom store from the context

  • Loading branch information...
commit aa96a45e2ac55763ddabda6279853784d3182884 1 parent ef8c05f
@tekwiz authored
Showing with 32 additions and 8 deletions.
  1. +22 −8 doc/storage.markdown
  2. +10 −0 lib/rack/cache/context.rb
View
30 doc/storage.markdown
@@ -73,18 +73,32 @@ Storage Registration
--------------------
If the needs for configuration your stores are more complex than the URIs allow,
-you may register a manually instantiated store. You can do this directly on the
-`Rack::Cache::Storage.instance` singleton, and pass the name as the `:metastore`
-and `entitystore` values in the rack configuration:
-
- Rack::Cache::Storage.instance.register_metastore :my_store,
+you may register a manually instantiated store. You can do this by calling the
+`register_metastore` and `register_entitystore` methods on the __Rack::Cache__
+instance when you set it up in your rack configuration.
+
+ use Rack::Cache do |rack_cache|
+ rack_cache.register_metastore, :my_metas,
+ ::Cache::MetaStore::Heap.new
+ rack_cache.register_entitystore, :my_entities,
+ ::Cache::EntityStore::Heap.new
+ rack_cache.use :metastore, :my_metas
+ rack_cache.use :entitystore, :my_entities
+ end
+
+You can also register storage instances directly on the`Rack::Cache::Storage.instance`
+singleton, and pass the name as the `:metastore` and `entitystore` values in the rack
+configuration:
+
+ Rack::Cache::Storage.instance.register_metastore :my_metas,
Rack::Cache::MetaStore::Heap.new
- Rack::Cache::Storage.instance.register_entitystore :my_store,
+ Rack::Cache::Storage.instance.register_entitystore :my_entities,
Rack::Cache::EntityStore::Heap.new
use Rack::Cache,
- :metastore => :my_store,
- :entitystore => :my_store
+ :metastore => :my_metas,
+ :entitystore => :my_entities
+
Storage Implementations
-----------------------
View
10 lib/rack/cache/context.rb
@@ -26,6 +26,11 @@ def initialize(backend, options={})
private_headers.map { |name| "HTTP_#{name.upcase.tr('-', '_')}" }
end
+ # Register a MetaStore instance. See Rack::Cache::Storage#register_metastore
+ def register_metastore(*args)
+ Storage.instance.register_metastore(*args)
+ end
+
# The configured MetaStore instance. Changing the rack-cache.metastore
# value effects the result of this method immediately.
def metastore
@@ -33,6 +38,11 @@ def metastore
storage.resolve_metastore(uri_or_name)
end
+ # Register an EntityStore instance. See Rack::Cache::Storage#register_entitystore
+ def register_entitystore(*args)
+ Storage.instance.register_entitystore(*args)
+ end
+
# The configured EntityStore instance. Changing the rack-cache.entitystore
# value effects the result of this method immediately.
def entitystore
Please sign in to comment.
Something went wrong with that request. Please try again.