Class: ESI::Fragment

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

Overview

Represents part of the cached page, typically an <esi:include

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, max_age, body) ⇒ Fragment

Returns a new instance of Fragment.



15
16
17
18
19
# File 'lib/esi/cache.rb', line 15

def initialize(uri,max_age,body)
  @uri = uri
  @max_age = Time.now.to_i + max_age.to_i
  @body = body
end

Instance Attribute Details

#bodyObject Also known as: read_body

Returns the value of attribute body.



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

def body
  @body
end

#max_ageObject

Returns the value of attribute max_age.



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

def max_age
  @max_age
end

#uriObject

Returns the value of attribute uri.



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

def uri
  @uri
end

Instance Method Details

#dupObject

make a copy of the object, necessary for thread safety



22
23
24
# File 'lib/esi/cache.rb', line 22

def dup
  Fragment.new( @uri, @max_age, @body )
end

#valid?Boolean

determine if the fragment is still valid, given the max age associated when the object was created

Returns:

  • (Boolean)


27
28
29
# File 'lib/esi/cache.rb', line 27

def valid?
  (Time.now.to_i < @max_age)
end