Class: MemcachePod::MemoryEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/memcachepod/memory_entry.rb

Instance Method Summary collapse

Constructor Details

#initialize(body, ttl) ⇒ MemoryEntry

Returns a new instance of MemoryEntry.



9
10
11
12
13
# File 'lib/memcachepod/memory_entry.rb', line 9

def initialize(body,ttl)
  @reference = false
  @body = body
  @expires_in = expires_in(ttl)
end

Instance Method Details

#bodyObject



20
21
22
23
# File 'lib/memcachepod/memory_entry.rb', line 20

def body()
  @reference = true
  return @body
end

#expired?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
# File 'lib/memcachepod/memory_entry.rb', line 25

def expired?()
  if 0 < @expires_in
    now = Time.now.to_i #second
    return @expires_in < now
  else
    return false
  end
end

#get_statusObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/memcachepod/memory_entry.rb', line 34

def get_status
  exp = 0
  if 0 < @expires_in
    exp = @expires_in - Time.now.to_i
  end
  return {
    'reference'  => @reference,
    'expires_in' => exp,
    'bodysize'   => @body.size
  }
end

#update(body, ttl) ⇒ Object



15
16
17
18
# File 'lib/memcachepod/memory_entry.rb', line 15

def update(body,ttl)
  @body = body
  @expires_in = expires_in(ttl)
end