Permalink
Browse files

Removed rails stuff, it's in new iron_cache_rails gem now.

  • Loading branch information...
1 parent c28263d commit f3de8b175529886e93caccd7071dc690858456a4 @treeder treeder committed Mar 27, 2013
Showing with 0 additions and 195 deletions.
  1. +0 −93 lib/action_dispatch/session/iron_cache.rb
  2. +0 −102 lib/active_support/cache/iron_cache_store.rb
@@ -1,93 +0,0 @@
-require 'iron_cache'
-require 'base64'
-require 'action_dispatch/middleware/session/abstract_store'
-
-module ActionDispatch
- module Session
- class IronCache < ActionDispatch::Session::AbstractStore
-
- def initialize(app, options = {})
- @options = options
- super
-
- @client = ::IronCache::Client.new(options)
- end
-
- def options
- @options
- end
-
- def get_session(env, session_id)
- item = nil
- session_id ||= generate_sid
-
- with_namespace(session_id, options) do |cache, k|
- item = cache.get(k)
- item = item.value unless item.nil?
- end
-
- session_data = deserialize_entry(item) rescue {}
-
- [session_id, session_data]
- end
-
- def set_session(env, session_id, session, options)
- with_namespace(session_id, options) do |cache, k|
- cache.put(k, serialize_entry(session, options), options)
- end
-
- session_id
- end
-
- def destroy_session(env, session_id, options)
- with_namespace(session_id, options) do |cache, k|
- cache.delete(k)
- end
-
- generate_sid
- end
-
- private
-
- def with_namespace(key, options)
- options[:namespace] ||= 'rails_cache'
-
- cache_name = options[:namespace]
-
- yield(@client.cache(cache_name), escape_key(key))
- end
-
- def escape_key(key)
- ekey = ::Base64.encode64(key)
-
- if ekey.size > 250
- ekey = "#{key[0, 213]}:md5:#{Digest::MD5.hexdigest(key)}"
- end
-
- ekey
- end
-
- def deserialize_entry(raw_value)
- if raw_value
- raw_value = ::Base64.decode64(raw_value) rescue raw_value
- Marshal.load(raw_value) rescue raw_value
- else
- nil
- end
- end
-
- def serialize_entry(entry, options)
- if options[:raw]
- if entry.respond_to?(:value)
- entry.value.to_s
- else
- entry.to_s
- end
- else
- ::Base64.encode64 Marshal.dump(entry)
- end
- end
-
- end
- end
-end
@@ -1,102 +0,0 @@
-require 'iron_cache'
-require 'base64'
-
-module ActiveSupport
- module Cache
- class IronCacheStore < ActiveSupport::Cache::Store
-
- def initialize(options = nil)
- super(options)
-
- @client = IronCache::Client.new(@options)
-
- extend ActiveSupport::Cache::Strategy::LocalCache
- end
-
- def increment(key, amount = 1, options = nil)
- with_namespace(key, options) do |cache, k|
- cache.increment(k, amount)
- end
- end
-
- def decrement(key, amount = 1, options = nil)
- with_namespace(key, options) do |cache, k|
- cache.increment(k, -amount)
- end
- end
-
- protected
-
- def read_entry(key, options)
- item = nil
-
- with_namespace(key, options) do |cache, k|
- item = cache.get(k)
- item = item.value unless item.nil?
- end
-
- deserialize_entry(item)
- end
-
- def write_entry(key, entry, options)
- with_namespace(key, options) do |cache, k|
- cache.put(k, serialize_entry(entry, options), options)
- end
-
- true
- end
-
- def delete_entry(key, options)
- with_namespace(key, options) do |cache, k|
- cache.delete(k)
- end
-
- true
- end
-
- private
-
- def with_namespace(key, options)
- options[:namespace] ||= 'rails_cache'
-
- cache_name, key_name = namespaced_key(key, options).split(':', 2)
-
- yield(@client.cache(cache_name), escape_key(key_name))
- end
-
- def escape_key(key)
- ekey = ::Base64.encode64(key)
-
- if ekey.size > 250
- ekey = "#{key[0, 213]}:md5:#{Digest::MD5.hexdigest(key)}"
- end
-
- ekey
- end
-
- def deserialize_entry(raw_value)
- if raw_value
- raw_value = ::Base64.decode64(raw_value) rescue raw_value
- entry = Marshal.load(raw_value) rescue raw_value
- entry.is_a?(ActiveSupport::Cache::Entry) ? entry : ActiveSupport::Cache::Entry.new(entry)
- else
- nil
- end
- end
-
- def serialize_entry(entry, options)
- value = nil
-
- if options[:raw]
- if entry.respond_to?(:value)
- value = entry.value.to_s
- else
- value = entry.to_s
- end
- else
- value = ::Base64.encode64 Marshal.dump(entry)
- end
- end
- end
- end
-end

2 comments on commit f3de8b1

@fred
fred commented on f3de8b1 Feb 6, 2014

Still need to remove reference to this code in "lib/iron_cache.rb"

require 'rest'
require "iron_cache/version"
require 'iron_cache/caches'
require 'iron_cache/items'
require 'iron_cache/client'

# session store
if defined? ActionDispatch
  require 'action_dispatch/session/iron_cache'
end

error:

/Users/fred/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:251:in `require': cannot load such file -- action_dispatch/session/iron_cache (LoadError)
@treeder
Member
treeder commented on f3de8b1 Feb 6, 2014

Done, 1.4.2.

Please sign in to comment.