Permalink
Browse files

Dispatch option parsing to strategy classes

  • Loading branch information...
1 parent 4d748e3 commit 86e29770f68f496dde8347312949313a34c2bcc8 @orslumen committed Dec 27, 2011
View
@@ -7,97 +7,97 @@ PATH
GEM
remote: http://rubygems.org/
specs:
- actionmailer (3.1.0)
- actionpack (= 3.1.0)
+ actionmailer (3.1.3)
+ actionpack (= 3.1.3)
mail (~> 2.3.0)
- actionpack (3.1.0)
- activemodel (= 3.1.0)
- activesupport (= 3.1.0)
+ actionpack (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
builder (~> 3.0.0)
erubis (~> 2.7.0)
i18n (~> 0.6)
- rack (~> 1.3.2)
- rack-cache (~> 1.0.3)
+ rack (~> 1.3.5)
+ rack-cache (~> 1.1)
rack-mount (~> 0.8.2)
rack-test (~> 0.6.1)
- sprockets (~> 2.0.0)
- activemodel (3.1.0)
- activesupport (= 3.1.0)
- bcrypt-ruby (~> 3.0.0)
+ sprockets (~> 2.0.3)
+ activemodel (3.1.3)
+ activesupport (= 3.1.3)
builder (~> 3.0.0)
i18n (~> 0.6)
- activerecord (3.1.0)
- activemodel (= 3.1.0)
- activesupport (= 3.1.0)
+ activerecord (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
arel (~> 2.2.1)
tzinfo (~> 0.3.29)
- activeresource (3.1.0)
- activemodel (= 3.1.0)
- activesupport (= 3.1.0)
- activesupport (3.1.0)
+ activeresource (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ activesupport (3.1.3)
multi_json (~> 1.0)
arel (2.2.1)
- bcrypt-ruby (3.0.1)
builder (3.0.0)
- database_cleaner (0.6.7)
+ database_cleaner (0.7.0)
diff-lcs (1.1.3)
erubis (2.7.0)
hike (1.2.1)
i18n (0.6.0)
+ json (1.6.3)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
- mime-types (1.16)
- multi_json (1.0.3)
- polyglot (0.3.2)
- rack (1.3.4)
- rack-cache (1.0.3)
+ mime-types (1.17.2)
+ multi_json (1.0.4)
+ polyglot (0.3.3)
+ rack (1.3.5)
+ rack-cache (1.1)
rack (>= 0.4)
rack-mount (0.8.3)
rack (>= 1.0.0)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
- rails (3.1.0)
- actionmailer (= 3.1.0)
- actionpack (= 3.1.0)
- activerecord (= 3.1.0)
- activeresource (= 3.1.0)
- activesupport (= 3.1.0)
+ rails (3.1.3)
+ actionmailer (= 3.1.3)
+ actionpack (= 3.1.3)
+ activerecord (= 3.1.3)
+ activeresource (= 3.1.3)
+ activesupport (= 3.1.3)
bundler (~> 1.0)
- railties (= 3.1.0)
- railties (3.1.0)
- actionpack (= 3.1.0)
- activesupport (= 3.1.0)
+ railties (= 3.1.3)
+ railties (3.1.3)
+ actionpack (= 3.1.3)
+ activesupport (= 3.1.3)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
- rake (0.9.2)
- rcov (0.9.10)
- rdoc (3.9.4)
+ rake (0.9.2.2)
+ rcov (0.9.11)
+ rdoc (3.11)
+ json (~> 1.4)
rr (1.0.4)
- rspec (2.6.0)
- rspec-core (~> 2.6.0)
- rspec-expectations (~> 2.6.0)
- rspec-mocks (~> 2.6.0)
- rspec-core (2.6.4)
- rspec-expectations (2.6.0)
+ rspec (2.7.0)
+ rspec-core (~> 2.7.0)
+ rspec-expectations (~> 2.7.0)
+ rspec-mocks (~> 2.7.0)
+ rspec-core (2.7.1)
+ rspec-expectations (2.7.0)
diff-lcs (~> 1.1.2)
- rspec-mocks (2.6.0)
- sprockets (2.0.2)
+ rspec-mocks (2.7.0)
+ sprockets (2.0.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (!= 1.3.0, ~> 1.1)
- sqlite3 (1.3.4)
+ sqlite3 (1.3.5)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
- tzinfo (0.3.30)
+ tzinfo (0.3.31)
PLATFORMS
ruby
View
@@ -7,7 +7,6 @@ Record Cache transparantly stores Records in a Cache Store and retrieve those Re
Cache invalidation is performed automatically when Records are created, updated or destroyed. Currently only Active Record is supported, but more
data stores may be added in the future.
-
Usage
-----
@@ -76,7 +75,7 @@ The following options are available:
_In case the same Record is (always) queried multiple times during a single request from different locations,
e.g. from a helper and from a model, the Record can be cached in the Request Scope by setting this option to +true+.
- **Important**: Add to application_controller.rb: `before_filter { |c| RecordCache::Strategy::RequestCache.clear }`
+ **Important**: Add to application_controller.rb: `prepend_before_filter { |c| RecordCache::Strategy::RequestCache.clear }`
Note: In most cases you should be able to use an instance variable in the controller (or helper) instead._
- <a name="index" />`:index`: An array of `:belongs_to` attributes to cache `:has_many` relations (default: `[]`)
@@ -244,10 +243,16 @@ Development
$ bundle
# run the specs
- $ rake
+ $ bundle exec rake spec
# run a single spec
$ bundle exec rspec ./spec/lib/strategy/base_spec.rb:61
+
+ # make sure Rails 3.0 support is also fine:
+ $ vi record-cache.gemspec
+ replace [">= 3.0"] with [">= 3.0"], "< 3.1"
+ $ bundle update
+ $ bundle exec rake spec
Deploying the gem:
@@ -258,5 +263,45 @@ Deploying the gem:
$ gem build record-cache.gemspec
$ gem push record-cache-0.1.1.gem
+Debugging the gem:
+
+Switch on DEBUG logging (`config.log_level = :debug` in development.rb) to get more information on cache hits and misses.
+
+
+Release Notes
+-------------
+
+#### Version 1.0
+
+First version, with the following Strategies:
+
+1. Request Cache
+1. ID Cache
+1. Index Cache
+
+#### Version 1.1
+
+Added support for Rails 3.1
+
+#### Version 1.2
+
+Refactoring: Moved Serialization, Sorting and Filtering to separate Util class.
+
+Now it is possible to re-use MySQL style sorting (with collation) in your own app, e.g. by calling `RecordCache::Strategy::Util.sort!(Apple.all, :name)`.
+
+#### Version 1.3
+
+Fixed Bugs:
+1. "\u0000" is also used by Arel as a parameter query binding marker.
+1. https://github.com/orslumen/record-cache/issues/2: bypassing record_cache when selecting rows with lock
+
+Added:
+1. Release Notes ;)
+1. https://github.com/orslumen/record-cache/pull/3: Ruby 1.9 fixes, has_one support, Remove Freeze for Dalli encoding (Bryan Mundie)
+1. :unique_index option
+1. :cache_all option
+
+And updated the gemspec file.
+
----
Copyright (c) 2011 Orslumen, released under the MIT license
View
@@ -29,16 +29,17 @@ def version_store=(store)
# The ActiveSupport::Cache::Store instance that contains the current record(group) versions.
# Note that it must point to a single Store shared by all webservers (defaults to Rails.cache)
def version_store
- @version_store ||= RecordCache::VersionStore.new(RecordCache::MultiRead.test(Rails.cache))
+ @version_store = Rails.cache unless @version_store
+ @version_store
end
-
- # Register a store with a specific id for reference with :store in +cache_records+
+
+ # Register a cache store by id for future reference with the :store option for +cache_records+
# e.g. RecordCache::Base.register_store(:server, ActiveSupport::Cache.lookup_store(:memory_store))
def register_store(id, store)
stores[id] = RecordCache::MultiRead.test(store)
end
- # The hash of stores (store_id => store)
+ # The hash of registered record stores (store_id => store)
def stores
@stores ||= {}
end
@@ -78,33 +79,30 @@ def without_record_cache(&block)
module ClassMethods
# Cache the instances of this model
- # options:
+ # generic options:
# :store => the cache store for the instances, e.g. :memory_store, :dalli_store* (default: Rails.cache)
# or one of the store ids defined using +RecordCache::Base.register_store+
# :key => provide a unique shorter key to limit the cache key length (default: model.name)
+ #
+ # cache strategy specific options:
# :index => one or more attributes (Symbols) for which the ids are cached for the value of the attribute
# :request_cache => Set to true in case the exact same query is executed more than once during a single request
# If set to true somewhere, make sure to add the following to your application controller:
- # before_filter { |c| RecordCache::Strategy::RequestCache.clear }
+ # prepend_before_filter { |c| RecordCache::Strategy::RequestCache.clear }
#
# Hints:
# - Dalli is a high performance pure Ruby client for accessing memcached servers, see https://github.com/mperham/dalli
# - use :store => :memory_store in case all records can easily fit in server memory
# - use :index => :account_id in case the records are (almost) always queried as a full set per account
# - use :index => :person_id for aggregated has_many associations
def cache_records(options = {})
- @rc_dispatcher = RecordCache::Dispatcher.new(self) unless defined?(@rc_dispatcher)
- store = RecordCache::MultiRead.test(options[:store] ? RecordCache::Base.stores[options[:store]] || ActiveSupport::Cache.lookup_store(options[:store]) : (defined?(::Rails) ? Rails.cache : ActiveSupport::Cache.lookup_store(:memory_store)))
- # always register an ID Cache
- record_cache.register(:id, ::RecordCache::Strategy::IdCache, store, options)
- # parse :index option
- [options[:index]].flatten.compact.map(&:to_sym).each do |index|
- record_cache.register(index, ::RecordCache::Strategy::IndexCache, store, options.merge({:index => index}))
+ unless @rc_dispatcher
+ @rc_dispatcher = RecordCache::Dispatcher.new(self)
+ # Callback for Data Store specific initialization
+ record_cache_init
end
- # parse :request_cache option
- record_cache.register(:request_cache, ::RecordCache::Strategy::RequestCache, store, options) if options[:request_cache]
- # Callback for Data Store specific initialization
- record_cache_init
+ # parse the requested strategies from the given options
+ @rc_dispatcher.parse(options)
end
# Returns true if record cache is defined and active for this class
Oops, something went wrong.

0 comments on commit 86e2977

Please sign in to comment.