Class: U3d::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/u3d/cache.rb

Overview

Cache stores the informations regarding versions

Constant Summary collapse

DEFAULT_LINUX_PATH =

Path to the directory containing the cache for the different OS

File.join(ENV['HOME'], '.u3d').freeze
DEFAULT_MAC_PATH =
File.join(ENV['HOME'], 'Library', 'Application Support', 'u3d').freeze
DEFAULT_WINDOWS_PATH =
File.join(ENV['HOME'], 'AppData', 'Local', 'u3d').freeze
DEFAULT_NAME =

Name of the file itself

'cache.json'.freeze
CACHE_LIFE =

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

60 * 60 * 24

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: nil, force_os: nil, force_refresh: false) ⇒ Cache

Returns a new instance of Cache.



54
55
56
57
58
59
60
61
62
63
# File 'lib/u3d/cache.rb', line 54

def initialize(path: nil, force_os: nil, force_refresh: false)
  @path = path || default_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)
  @cache = data
  overwrite_cache(file_path, os) if need_update || force_refresh
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



47
48
49
# File 'lib/u3d/cache.rb', line 47

def path
  @path
end

Instance Method Details

#[](key) ⇒ Object



49
50
51
52
# File 'lib/u3d/cache.rb', line 49

def [](key)
  return nil if @cache[key].nil?
  @cache[key]
end