Sha256: 5b44dce7963cb7ae36b24776ea5e50aa4b2887c1d59afed0cf47d00494fd73d0

Contents?: true

Size: 1.53 KB

Versions: 25

Compression:

Stored size: 1.53 KB

Contents

require 'cgi'
require 'cgi/session'

class CGI #:nodoc:#
  class Session #:nodoc:#
    # Allows Rails to use Cachetastic for it's session store.
    # The setting below needs to happen AFTER the gem has been required, obviously!
    # In Rails 1.2.6 this is AFTER the initializer block.
    #   ActionController::Base.session_store = :cachetastic_store
    class CachetasticStore


      def check_id(id) #:nodoc:#
        /[^0-9a-zA-Z]+/ =~ id.to_s ? false : true
      end
      
      def initialize(session, options = {}) #:nodoc:#
        id = session.session_id
        unless check_id(id)
          raise ArgumentError, "session_id '%s' is invalid" % id
        end
        
        @session_key = id
        
        @session_data = {}
      end
 
      # Restore session state from the session's memcache entry.
      #
      # Returns the session state as a hash.
      def restore #:nodoc:#
        @session_data = Cachetastic::Caches::RailsSessionCache.get(@session_key) do
          {}
        end
      end

      # Save session state to the session's memcache entry.
      def update #:nodoc:#
        Cachetastic::Caches::RailsSessionCache.set(@session_key, @session_data)
      end
    
      # Update and close the session's memcache entry.
      def close #:nodoc:#
        update
      end

      # Delete the session's memcache entry.
      def delete #:nodoc:#
        Cachetastic::Caches::RailsSessionCache.delete(@session_key)
        @session_data = {}
      end
      
      def data #:nodoc:#
        @session_data
      end

    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
cachetastic-1.5.0 lib/rails_extensions/cgi_session_cachetastic_store.rb
cachetastic-1.6.0 lib/rails_extensions/cgi_session_cachetastic_store.rb
cachetastic-1.7.0 lib/rails_extensions/cgi_session_cachetastic_store.rb
cachetastic-1.7.3 lib/rails_extensions/cgi_session_cachetastic_store.rb
cachetastic-1.1.8 lib/rails_extensions/cgi_session_cachetastic_store.rb
cachetastic-1.4.0 lib/rails_extensions/cgi_session_cachetastic_store.rb
cachetastic-1.7.4 lib/rails_extensions/cgi_session_cachetastic_store.rb
cachetastic-1.7.2 lib/rails_extensions/cgi_session_cachetastic_store.rb
cachetastic-1.2.1 lib/rails_extensions/cgi_session_cachetastic_store.rb
cachetastic-1.2.2 lib/rails_extensions/cgi_session_cachetastic_store.rb
cachetastic-1.2.3 lib/rails_extensions/cgi_session_cachetastic_store.rb
cachetastic-1.2.7.1 lib/rails_extensions/cgi_session_cachetastic_store.rb
cachetastic-1.3.0 lib/rails_extensions/cgi_session_cachetastic_store.rb
cachetastic-1.3.1 lib/rails_extensions/cgi_session_cachetastic_store.rb
cachetastic-1.4.1 lib/rails_extensions/cgi_session_cachetastic_store.rb
cachetastic-1.4.2 lib/rails_extensions/cgi_session_cachetastic_store.rb
cachetastic-2.1.4 lib/cachetastic/rails_extensions/cgi_session_store.rb
cachetastic-2.1.2 lib/cachetastic/rails_extensions/cgi_session_store.rb
cachetastic-2.1.3 lib/cachetastic/rails_extensions/cgi_session_store.rb
cachetastic-2.0.0 lib/cachetastic/rails_extensions/cgi_session_store.rb