Sha256: 6dc3b8e78e1a02c35096b0e153ebad9950f3c41f5d5770ed327831aae1af61f3

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

# = Fragment
#
# A Fragment is the output of a rendered script. Additional metadata 
# such as lastmodified and expire times are stored to facilitate 
# fragment processing (for example caching).
#
# === Design:
#
# Fragments are cached in the filesystem to allow for a cluster of
# server to access them. Benefits over the older memory cache scheme:
#
# - each fragment is processed once by one server
# - easier visualisation of the fragments.
# - can clear the cache for all server
# - can selectively invalidate one fragment!
# - less memory per server
# - can run background cron scripts over the fragments (compression)
#
# code:: gmosx
#
# (c) 2004 Navel, all rights reserved.
# $Id: fragment.rb 71 2004-10-18 10:50:22Z gmosx $

require "n/utils/cache"
require "n/mixins"

module N; module App

class Fragment
	include N::Expirable
	include N::LRUCache::Item

	# precompiled flags for fragment key "customization"

	ADMIN_FLAG = "-a"
	OWNER_FLAG = "-o"
	EDITOR_FLAG = "-e"
	VIEWER_FLAG = "-f"
	MY_FLAG = "-m"
	ANONYMOUS_FLAG = "-n"

	attr_accessor :body, :lm
	
	# another method for invalidation, allows for more flexible
	# invalidation strategies. also used by the legacy autoinvalidate
	# code.
	attr_accessor :expires

	def initialize(body = "", lm = Time.now)
		@body = body
		@lm = lm
	end

	def expires_after!(ea = (60*60*24))
		@expires = @lm + ea
	end

	def expired?
		return true if @expires.nil? || (Time.now > @expires)
	end

	def to_str
		return @body
	end	
end

end; end # module

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nitro-0.1.2 lib/n/app/fragment.rb