5 # this allows caching of the fact that there is nothing in the remote cache
6 NULL
= 'remote_cache_store:null'
9 Thread
.current
[thread_local_key
] = MemoryStore
.new
12 Thread
.current
[thread_local_key
] = nil
18 klass
.class_eval(<<-EOS, __FILE__, __LINE__)
24 Thread.current[:#{thread_local_key}] = MemoryStore.new
27 Thread.current[:#{thread_local_key}] = nil
34 def read(key
, options
= nil)
35 value
= local_cache
&& local_cache
.read(key
)
40 local_cache
.write(key
, value
|| NULL
) if local_cache
43 # forcing the value to be immutable
44 value
.duplicable
? ? value
.dup
: value
48 def write(key
, value
, options
= nil)
49 value
= value
.to_s
if respond_to
?(:raw?) && raw
?(options
)
50 local_cache
.write(key
, value
|| NULL
) if local_cache
54 def delete(key
, options
= nil)
55 local_cache
.write(key
, NULL
) if local_cache
59 def exist(key
, options
= nil)
60 value
= local_cache
.read(key
) if local_cache
70 def increment(key
, amount
= 1)
72 local_cache
.write(key
, value
.to_s
) if local_cache
79 def decrement(key
, amount
= 1)
81 local_cache
.write(key
, value
.to_s
) if local_cache
89 local_cache
.clear
if local_cache
95 @thread_local_key ||= "#{self.class.name.underscore}_local_cache".gsub("/", "_").to_sym
99 Thread
.current
[thread_local_key
]