Sha256: 028ca5ce30a3f6419559b4bbd46b196d420343a034c7673ec549e2639c1c9e19
Contents?: true
Size: 1.34 KB
Versions: 41
Compression:
Stored size: 1.34 KB
Contents
require 'monitor' require File.join(File.dirname(__FILE__), 'abstract_session_proxy') module Sunspot module SessionProxy # # This class implements a session proxy that creates a different Session # object for each thread. Any multithreaded application should use this # proxy. # class ThreadLocalSessionProxy < AbstractSessionProxy FINALIZER = Proc.new do |object_id| Thread.current[:"sunspot_session_#{object_id}"] = nil end # The configuration with which the thread-local sessions are initialized. attr_reader :config @@next_id = 0 delegate :batch, :commit, :commit_if_delete_dirty, :commit_if_dirty, :delete_dirty?, :dirty?, :index, :index!, :new_search, :optimize, :remove, :remove!, :remove_all, :remove_all!, :remove_by_id, :remove_by_id!, :search, :more_like_this, :new_more_like_this, :to => :session # # Optionally pass an existing Sunspot::Configuration object. If none is # passed, a default configuration is used; it can then be modified using # the #config attribute. # def initialize(config = Sunspot::Configuration.new) @config = config ObjectSpace.define_finalizer(self, FINALIZER) end def session #:nodoc: Thread.current[:"sunspot_session_#{object_id}"] ||= Session.new(config) end end end end
Version data entries
41 entries across 41 versions & 9 rubygems