Module: Yescode::RequestCache

Defined in:
lib/yescode/request_cache.rb,
lib/yescode/request_cache/middleware.rb

Defined Under Namespace

Classes: Middleware

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



51
52
53
# File 'lib/yescode/request_cache.rb', line 51

def self.[](key)
  store[key]
end

.[]=(key, value) ⇒ Object



59
60
61
# File 'lib/yescode/request_cache.rb', line 59

def self.[]=(key, value)
  store[key] = value
end

.active?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/yescode/request_cache.rb', line 43

def self.active?
  Thread.current[:request_cache_active] || false
end

.begin!Object



35
36
37
# File 'lib/yescode/request_cache.rb', line 35

def self.begin!
  Thread.current[:request_cache_active] = true
end

.clear!Object



31
32
33
# File 'lib/yescode/request_cache.rb', line 31

def self.clear!
  Thread.current[:request_cache] = {}
end

.delete(key, &block) ⇒ Object



72
73
74
# File 'lib/yescode/request_cache.rb', line 72

def self.delete(key, &block)
  store.delete(key, &block)
end

.end!Object



39
40
41
# File 'lib/yescode/request_cache.rb', line 39

def self.end!
  Thread.current[:request_cache_active] = false
end

.exist?(key) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/yescode/request_cache.rb', line 63

def self.exist?(key)
  store.key?(key)
end

.fetch(key) ⇒ Object



67
68
69
70
# File 'lib/yescode/request_cache.rb', line 67

def self.fetch(key)
  store[key] = yield unless exist?(key)
  store[key]
end

.read(key) ⇒ Object



47
48
49
# File 'lib/yescode/request_cache.rb', line 47

def self.read(key)
  store[key]
end

.storeObject



23
24
25
# File 'lib/yescode/request_cache.rb', line 23

def self.store
  Thread.current[:request_cache] ||= {}
end

.store=(store) ⇒ Object



27
28
29
# File 'lib/yescode/request_cache.rb', line 27

def self.store=(store)
  Thread.current[:request_cache] = store
end

.write(key, value) ⇒ Object



55
56
57
# File 'lib/yescode/request_cache.rb', line 55

def self.write(key, value)
  store[key] = value
end