Class: Pione::System::FileCache::SimpleCacheMethod

Inherits:
FileCacheMethod show all
Defined in:
lib/pione/system/file-cache.rb

Overview

SimpleCacheMethod is a simple cache method implementation.

Instance Method Summary collapse

Constructor Details

#initializeSimpleCacheMethod

Creates a method.



130
131
132
133
# File 'lib/pione/system/file-cache.rb', line 130

def initialize
  @table = {}
  @tmpdir = Global.file_cache_directory
end

Instance Method Details

#cached?(location) ⇒ Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/pione/system/file-cache.rb', line 159

def cached?(location)
  @table.has_key?(location)
end

#clearObject



163
164
165
# File 'lib/pione/system/file-cache.rb', line 163

def clear
  @table.clear
end

#get(location) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/pione/system/file-cache.rb', line 135

def get(location)
  # cache if record doesn't exist
  unless @table.has_key?(location)
    cache_location = Location[Global.file_cache_path_generator.create]
    location.turn(cache_location)
    @table[location] = cache_location
  end
  unless @table[location].exist?
    location.turn(@table[location])
  end
  return @table[location]
end

#put(src, dest) ⇒ Object



148
149
150
151
# File 'lib/pione/system/file-cache.rb', line 148

def put(src, dest)
  # make cache from source and link between cache and destination
  @table[dest] = get(src).tap{|cache_location| cache_location.turn(dest)}
end

#sync(old_location, new_location) ⇒ Object



153
154
155
156
157
# File 'lib/pione/system/file-cache.rb', line 153

def sync(old_location, new_location)
  if cache_location = @table[old_location]
    @table[new_location] = cache_location
  end
end