Class: Gap::Cache
- Inherits:
-
Object
- Object
- Gap::Cache
- Defined in:
- lib/gap50/cache/cache.rb
Instance Method Summary collapse
- #[](a) ⇒ Object
- #[]=(a, b) ⇒ Object
- #each ⇒ Object
- #fromBase64(b64) ⇒ Object
- #fromMarshal(text) ⇒ Object
- #has?(a) ⇒ Boolean
-
#initialize(filename) ⇒ Cache
constructor
A new instance of Cache.
- #load ⇒ Object
- #remove(key) ⇒ Object
- #save ⇒ Object
- #toBase64 ⇒ Object
- #toMarshal ⇒ Object
- #transaction ⇒ Object
Constructor Details
#initialize(filename) ⇒ Cache
Returns a new instance of Cache.
3 4 5 6 |
# File 'lib/gap50/cache/cache.rb', line 3 def initialize(filename) @filename = filename _load_or_create end |
Instance Method Details
#[](a) ⇒ Object
24 25 26 |
# File 'lib/gap50/cache/cache.rb', line 24 def [](a) @hash[a] end |
#[]=(a, b) ⇒ Object
36 37 38 |
# File 'lib/gap50/cache/cache.rb', line 36 def []=(a, b) @hash[a] = b end |
#each ⇒ Object
48 49 50 51 52 |
# File 'lib/gap50/cache/cache.rb', line 48 def each @hash.each{|k, v| yield k, v } end |
#fromBase64(b64) ⇒ Object
8 9 10 |
# File 'lib/gap50/cache/cache.rb', line 8 def fromBase64(b64) @hash = Marshal.load(b64.unpack("m").first) end |
#fromMarshal(text) ⇒ Object
16 17 18 |
# File 'lib/gap50/cache/cache.rb', line 16 def fromMarshal(text) @hash = Marshal.load(text) end |
#has?(a) ⇒ Boolean
32 33 34 |
# File 'lib/gap50/cache/cache.rb', line 32 def has?(a) @hash.include?(a) end |
#load ⇒ Object
40 41 42 |
# File 'lib/gap50/cache/cache.rb', line 40 def load _load_or_create end |
#remove(key) ⇒ Object
28 29 30 |
# File 'lib/gap50/cache/cache.rb', line 28 def remove(key) @hash.delete key end |
#save ⇒ Object
44 45 46 |
# File 'lib/gap50/cache/cache.rb', line 44 def save _save end |
#toBase64 ⇒ Object
12 13 14 |
# File 'lib/gap50/cache/cache.rb', line 12 def toBase64 [Marshal.dump(@hash)].pack("m") end |
#toMarshal ⇒ Object
20 21 22 |
# File 'lib/gap50/cache/cache.rb', line 20 def toMarshal Marshal.dump @hash end |
#transaction ⇒ Object
54 55 56 57 58 59 |
# File 'lib/gap50/cache/cache.rb', line 54 def transaction load ret = yield self save ret end |