Parent

Files

SynCache::CacheEntry

Attributes

sync[R]

use this to synchronize access to value

ttl[RW]

change this to make the entry expire sooner

value[RW]

stores the value object

Public Class Methods

new(ttl = nil, value = nil) click to toggle source
# File lib/syncache/syncache.rb, line 19
def initialize(ttl = nil, value = nil)
  @value = value
  @ttl = ttl
  @dirty = false
  record_access

  @sync = Mutex.new
end

Public Instance Methods

expire_at(time) click to toggle source

mark entry as dirty and schedule it to expire at given time

# File lib/syncache/syncache.rb, line 58
def expire_at(time)
  @expires = time if @expires > time
  @dirty = true
end
record_access() click to toggle source

record the fact that the entry was accessed

# File lib/syncache/syncache.rb, line 39
def record_access
  return if @dirty
  @expires = Time.now + (@ttl or FOREVER)
end
replacement_index() click to toggle source

entries with lowest index will be replaced first

# File lib/syncache/syncache.rb, line 46
def replacement_index
  @expires
end
stale?() click to toggle source

check if entry is stale

# File lib/syncache/syncache.rb, line 52
def stale?
  @expires < Time.now
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.