Created
August 10, 2015 07:09
-
-
Save bbozo/f5c28fe9bd804dff0af8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
session = {} | |
# see https://github.com/mperham/dalli | |
def common_cache | |
@common_cache ||= Dalli::Client.new('localhost:11211', { :namespace => "all_apps", :compress => true }) | |
end | |
def session.[] (arg) | |
if arg.to_s == 'access_token' | |
@access_token ||= common_cache.get("sessions/#{self[:user_id]}") | |
else | |
super(arg) | |
end | |
end | |
def session.[]= (arg, value) | |
if arg.to_s == 'access_token' | |
binding.pry | |
common_cache.set("sessions/#{self[:user_id]}", value) | |
@access_token = value | |
else | |
super(arg, value) | |
end | |
end | |
session[:user_id] = 23323 | |
session[:access_token] = 'rkhuhwiwuhiewrhwekjnewu4yuin' | |
puts session[:user_id] # returns from session | |
puts session[:access_token] # returns from memcache | |
puts session |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment