From 01801590f7a68a761118238a3c4f6e24936cebcf Mon Sep 17 00:00:00 2001 From: Pulkit Bhatia Date: Mon, 20 Jun 2016 21:23:06 +0530 Subject: [PATCH] added code to delete entry from concurrent hash(need review) --- lib/reel/session/store.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/reel/session/store.rb b/lib/reel/session/store.rb index 7dfe2ad..50d61cb 100644 --- a/lib/reel/session/store.rb +++ b/lib/reel/session/store.rb @@ -5,6 +5,7 @@ module Reel module Session class Store include Crypto + include Celluloid def initialize request @@ -32,11 +33,20 @@ def generate_id Celluloid::Internals::UUID.generate end + # start Celluloid timer to delete value from concurrent hash after expiry + def start_timer + return unless @key + @delete_time = after(@config[:session_length]){ + @store.delete @key if @store + } + end + def save - return nil if @val.empty? + return if @val.empty? # merge key,value - @key ||= generate_id + @key = generate_id @store.merge!({@key=>@val}) + start_timer @key end