Module: Pione::System::FileCache

Defined in:
lib/pione/system/file-cache.rb

Overview

FileCache is a caching system for task workers.

Defined Under Namespace

Classes: FileCacheMethod, NoCacheMethod, SimpleCacheMethod

Class Method Summary collapse

Class Method Details

.cache_methodClass

Return file cache class.

Returns:

  • (Class)

    CacheMethod class



9
10
11
# File 'lib/pione/system/file-cache.rb', line 9

def self.cache_method
  @klass || SimpleCacheMethod
end

.cached?(location) ⇒ Boolean

Return true if the location is cached.

Returns:

  • (Boolean)

    true if the location is cached



79
80
81
# File 'lib/pione/system/file-cache.rb', line 79

def self.cached?(location)
  instance.cached?(location)
end

.clearvoid

This method returns an undefined value.

Clear cache.



86
87
88
# File 'lib/pione/system/file-cache.rb', line 86

def self.clear
  instance.clear
end

.get(location) ⇒ BasicLocation

Get cached data location of the location. If the location is not cached and needs to be cached, create the cache and return it. If not, return the location as is.

Parameters:

  • location (BasicLocation)

    data location

Returns:

  • (BasicLocation)

    cached location



49
50
51
# File 'lib/pione/system/file-cache.rb', line 49

def self.get(location)
  instance.get(location)
end

.instanceCacheMethod

Return the singleton.

Returns:

  • (CacheMethod)

    cache method instance



37
38
39
# File 'lib/pione/system/file-cache.rb', line 37

def self.instance
  @instance ||= cache_method.new
end

.put(src, location) ⇒ void

This method returns an undefined value.

Put the data to the location and caches it.

Parameters:

  • src (String)

    source path

  • location (BasicLocation)

    destination location



60
61
62
# File 'lib/pione/system/file-cache.rb', line 60

def self.put(src, location)
  instance.put(src, location)
end

.register_file_cache_method(name, klass) ⇒ void

This method returns an undefined value.

Register the file cache method with the name.

Parameters:

  • name (Symbol)

    the name of file cache method

  • klass (FileCacheMethod)

    file cache method class



97
98
99
# File 'lib/pione/system/file-cache.rb', line 97

def self.register_file_cache_method(name, klass)
  (@file_cache_method ||= {})[name] = klass
end

.set_cache_method(file_cache_method) ⇒ void

This method returns an undefined value.

Set a file cache method.

Parameters:

  • klass (Class)

    CacheMethod class



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pione/system/file-cache.rb', line 18

def self.set_cache_method(file_cache_method)
  case file_cache_method
  when Symbol
    if klass = @file_cache_method[file_cache_method]
      @klass = klass
    else
      raise ArgumentError.new(file_cache_method)
    end
  when Class
    @klass = file_cache_method
  else
    raise ArgumentError.new(file_cache_method)
  end
end

.sync(old_location, new_location) ⇒ void

This method returns an undefined value.

Synchronize cache of old location with new location.

Parameters:

  • old_location (BasicLocation)

    old data location

  • new_location (BasicLocation)

    new data location



71
72
73
# File 'lib/pione/system/file-cache.rb', line 71

def self.sync(old_location, new_location)
  instance.sync(old_location, new_location)
end