class Stormpath::Cache::Cache

Attributes

stats[R]
tti_seconds[R]
ttl_seconds[R]

Public Class Methods

new(opts = {}) click to toggle source
   # File lib/stormpath-sdk/cache/cache.rb
10 def initialize(opts = {})
11   @ttl_seconds = opts[:ttl_seconds] || DEFAULT_TTL_SECONDS
12   @tti_seconds = opts[:tti_seconds] || DEFAULT_TTI_SECONDS
13   store_opts = opts[:store_opts] || {}
14   @store = (opts[:store] || DEFAULT_STORE).new(store_opts)
15   @stats = CacheStats.new
16 end

Public Instance Methods

clear() click to toggle source
   # File lib/stormpath-sdk/cache/cache.rb
45 def clear
46   @store.clear
47 end
delete(k) click to toggle source
   # File lib/stormpath-sdk/cache/cache.rb
40 def delete(k)
41   @store.delete(k)
42   @stats.delete
43 end
get(k) click to toggle source
   # File lib/stormpath-sdk/cache/cache.rb
18 def get(k)
19   if entry = @store.get(k)
20     if entry.expired? @ttl_seconds, @tti_seconds
21       @stats.miss true
22       @store.delete(k)
23       nil
24     else
25       @stats.hit
26       entry.touch
27       entry.value
28     end
29   else
30     @stats.miss
31     nil
32   end
33 end
put(k, v) click to toggle source
   # File lib/stormpath-sdk/cache/cache.rb
35 def put(k, v)
36   @store.put k, CacheEntry.new(v)
37   @stats.put
38 end
size() click to toggle source
   # File lib/stormpath-sdk/cache/cache.rb
49 def size
50   @stats.size
51 end