class Pione::System::FileCache::SimpleCacheMethod
SimpleCacheMethod
is a simple cache method implementation.
Public Class Methods
new()
click to toggle source
Creates a method.
# File lib/pione/system/file-cache.rb, line 172 def initialize @table = {} @tmpdir = Global.file_cache_directory end
Public Instance Methods
cached?(location)
click to toggle source
# File lib/pione/system/file-cache.rb, line 213 def cached?(location) @table.has_key?(location) end
clear()
click to toggle source
# File lib/pione/system/file-cache.rb, line 217 def clear @table.clear end
get(location)
click to toggle source
# File lib/pione/system/file-cache.rb, line 177 def get(location) # cache if record doesn't exist unless @table.has_key?(location) if not(location.local?) # create a cache and copy the location data to it cache_location = Location[Global.file_cache_path_generator.create] location.copy(cache_location) @table[location] = cache_location else # refer directly if the location is in local @table[location] = location end end unless @table[location].exist? location.turn(@table[location]) end return @table[location] end
put(src, dest)
click to toggle source
# File lib/pione/system/file-cache.rb, line 196 def put(src, dest) cache_location = @table[dest] # update cache if if cache_location.nil? or src.mtime > cache_location.mtime cache_location = Location[Global.file_cache_path_generator.create] src.copy(cache_location) @table[dest] = cache_location end end
sync(old_location, new_location)
click to toggle source
# File lib/pione/system/file-cache.rb, line 207 def sync(old_location, new_location) if cached?(old_location) @table[new_location] = @table[old_location] end end