Class: Gap::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/gap50/cache/cache.rb

Instance Method Summary collapse

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

#eachObject



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

Returns:

  • (Boolean)


32
33
34
# File 'lib/gap50/cache/cache.rb', line 32

def has?(a)
    @hash.include?(a)
end

#loadObject



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

#saveObject



44
45
46
# File 'lib/gap50/cache/cache.rb', line 44

def save
    _save
end

#toBase64Object



12
13
14
# File 'lib/gap50/cache/cache.rb', line 12

def toBase64
    [Marshal.dump(@hash)].pack("m")
end

#toMarshalObject



20
21
22
# File 'lib/gap50/cache/cache.rb', line 20

def toMarshal
    Marshal.dump @hash
end

#transactionObject



54
55
56
57
58
59
# File 'lib/gap50/cache/cache.rb', line 54

def transaction
    load
    ret = yield self
    save
    ret
end