Class: KeepYourHead::CacheItem

Inherits:
Object
  • Object
show all
Defined in:
lib/Keepyourhead/Cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache, success, filenames, lastAccess) ⇒ CacheItem

Returns a new instance of CacheItem.



23
24
25
26
27
# File 'lib/Keepyourhead/Cache.rb', line 23

def initialize(cache, success, filenames, lastAccess)
	self.cache, self.success,self.filenames, self.lastAccess = cache, success, filenames, lastAccess

	calculateSize
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



21
22
23
# File 'lib/Keepyourhead/Cache.rb', line 21

def cache
  @cache
end

#filenamesObject

Returns the value of attribute filenames.



21
22
23
# File 'lib/Keepyourhead/Cache.rb', line 21

def filenames
  @filenames
end

#lastAccessObject

Returns the value of attribute lastAccess.



21
22
23
# File 'lib/Keepyourhead/Cache.rb', line 21

def lastAccess
  @lastAccess
end

#sizeObject

Returns the value of attribute size.



21
22
23
# File 'lib/Keepyourhead/Cache.rb', line 21

def size
  @size
end

#successObject

Returns the value of attribute success.



21
22
23
# File 'lib/Keepyourhead/Cache.rb', line 21

def success
  @success
end

Instance Method Details

#calculateSizeObject



29
30
31
# File 'lib/Keepyourhead/Cache.rb', line 29

def calculateSize
	self.size = (self.filenames && self.filenames.map { |filename| ::File.size?(filename) }.inject(0) { |a,b| a + b }) || 0
end

#ok?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/Keepyourhead/Cache.rb', line 33

def ok?
	self.filenames.map{ |filename|
		File.exist?(filename)
	}.inject(true) { |a,b| a and b }
end

#old?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
# File 'lib/Keepyourhead/Cache.rb', line 39

def old?
	now = Time.new

	now - self.lastAccess > Cache::MaxAge
end

#removeObject



45
46
47
48
49
50
51
# File 'lib/Keepyourhead/Cache.rb', line 45

def remove
	@cache.delete key
	
	filenames.each { |filename|
		File.delete filename if File.exist?(filename)
	}
end