Global scoped variables. This is backed by a Cache store.
Methods
Attributes
| [RW] | cache | The global cache (store). |
Public Class methods
[ show source ]
# File lib/raw/context/global.rb, line 82
82: def delete(key)
83: Global.cache.delete(key)
84: end
[ show source ]
# File lib/raw/context/global.rb, line 61
61: def get(key)
62: return Global.cache[key]
63: end
Initialize a global value once.
[ show source ]
# File lib/raw/context/global.rb, line 50
50: def init(key, value)
51: unless Global[key]
52: Global[key] = value
53: end
54: end
[ show source ]
# File lib/raw/context/global.rb, line 56
56: def set(key, value)
57: Global.cache[key] = value
58: end
Init the correct Global cache.
[ show source ]
# File lib/raw/context/global.rb, line 34
34: def setup(type = Global.cache_type)
35: return if Global.cache
36:
37: case type
38: when :memory
39: require 'glue/cache/memory'
40: Global.cache = Glue::MemoryCache.new
41:
42: when :drb
43: require 'glue/cache/drb'
44: Global.cache = DrbCache.new(Global.cache_address, Global.cache_port)
45: end
46: end
If block is given it acts as an update methods, that transparently handles distributed stores.
Global.update(:USERS) do |users|
users << 'gmosx'
end
[ show source ]
# File lib/raw/context/global.rb, line 73
73: def update(key)
74: if block_given?
75: # update, also handles distributed stores.
76: val = Global.cache[key]
77: yield val
78: Global.cache[key] = val
79: end
80: end