lib/kasket.rb in kasket-0.6.4 vs lib/kasket.rb in kasket-0.7.0

- old
+ new

@@ -3,64 +3,36 @@ require 'active_support' require 'kasket/active_record_patches' module Kasket - autoload :Cache, 'kasket/cache' autoload :ConfigurationMixin, 'kasket/configuration_mixin' autoload :ReloadAssociationMixin, 'kasket/reload_association_mixin' autoload :RackMiddleware, 'kasket/rack_middleware' autoload :Query, 'kasket/query' CONFIGURATION = {:max_collection_size => 100} class Version MAJOR = 0 - MINOR = 6 - PATCH = 4 + MINOR = 7 + PATCH = 0 STRING = "#{MAJOR}.#{MINOR}.#{PATCH}" end module_function - def cache - Thread.current["kasket_cache"] ||= Cache.new - end - def setup(options = {}) CONFIGURATION[:max_collection_size] = options[:max_collection_size] if options[:max_collection_size] ActiveRecord::Base.extend(Kasket::ConfigurationMixin) ActiveRecord::Associations::BelongsToAssociation.send(:include, Kasket::ReloadAssociationMixin) ActiveRecord::Associations::BelongsToPolymorphicAssociation.send(:include, Kasket::ReloadAssociationMixin) ActiveRecord::Associations::HasOneThroughAssociation.send(:include, Kasket::ReloadAssociationMixin) + end - #sets up local cache clearing before each request. - #this is done to make it work for non rack rails and for functional tests - begin - ApplicationController.before_filter do - Kasket.cache.clear_local - end - rescue NameError => e - puts('WARNING: The kasket before filter did not register (this is OK in the test environment)') - end - - #sets up local cache clearing on rack - begin - ActionController::Dispatcher.middleware.use(Kasket::RackMiddleware) - rescue NameError => e - puts('WARNING: The kasket rack middleware is not in your rack stack (this is OK in the test environment)') - end - - #sets up local cache clearing after each test case - begin - ActiveSupport::TestCase.class_eval do - setup :clear_cache - def clear_cache - Kasket.cache.clear_local - Rails.cache.clear if Rails.cache.respond_to?(:clear) - end - end - rescue NameError => e + def clear_local + if Rails.cache.respond_to?(:with_local_cache) + Rails.cache.send(:local_cache).try(:clear) end end end