class U3d::Cache

Cache stores the informations regarding versions

Constants

CACHE_LIFE

Maximum duration after which the cache is considered outdated Currently set to 24h

DEFAULT_NAME

Name of the cache file

GLOBAL_CACHE_URL

Attributes

cache[RW]
path[RW]

Public Class Methods

default_os_path() click to toggle source
# File lib/u3d/cache.rb, line 71
def self.default_os_path
  U3dCore::Helper.data_path
end
new(path: nil, force_os: nil, force_refresh: false, offline: false, central_cache: false) click to toggle source
# File lib/u3d/cache.rb, line 55
def initialize(path: nil, force_os: nil, force_refresh: false, offline: false, central_cache: false)
  raise "Cache: cannot specify both offline and force_refresh" if offline && force_refresh
  @path = path || Cache.default_os_path
  @cache = {}
  os = force_os || U3dCore::Helper.operating_system
  Utils.ensure_dir(@path)
  file_path = File.expand_path(DEFAULT_NAME, @path)
  need_update, data = check_for_update(file_path, os)
  if offline
    UI.verbose("Cache outdated but we are working offline, so no updating it.")
    need_update = false
  end
  @cache = data
  overwrite_cache(file_path, os, central_cache: central_cache) if need_update || force_refresh
end

Public Instance Methods

[](key) click to toggle source
# File lib/u3d/cache.rb, line 50
def [](key)
  return nil if @cache[key].nil?
  @cache[key]
end