Class: Pione::System::FileCache::SimpleCacheMethod
- Inherits:
-
FileCacheMethod
- Object
- FileCacheMethod
- Pione::System::FileCache::SimpleCacheMethod
- Defined in:
- lib/pione/system/file-cache.rb
Overview
SimpleCacheMethod is a simple cache method implementation.
Instance Method Summary collapse
- #cached?(location) ⇒ Boolean
- #clear ⇒ Object
- #get(location) ⇒ Object
-
#initialize ⇒ SimpleCacheMethod
constructor
Creates a method.
- #put(src, dest) ⇒ Object
- #sync(old_location, new_location) ⇒ Object
Methods inherited from FileCacheMethod
Constructor Details
#initialize ⇒ SimpleCacheMethod
Creates a method.
172 173 174 175 |
# File 'lib/pione/system/file-cache.rb', line 172 def initialize @table = {} @tmpdir = Global.file_cache_directory end |
Instance Method Details
#cached?(location) ⇒ Boolean
213 214 215 |
# File 'lib/pione/system/file-cache.rb', line 213 def cached?(location) @table.has_key?(location) end |
#clear ⇒ Object
217 218 219 |
# File 'lib/pione/system/file-cache.rb', line 217 def clear @table.clear end |
#get(location) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# 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) ⇒ Object
196 197 198 199 200 201 202 203 204 205 |
# 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) ⇒ Object
207 208 209 210 211 |
# 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 |