Class: U3d::Cache
- Inherits:
-
Object
- Object
- U3d::Cache
- Defined in:
- lib/u3d/cache.rb
Overview
Cache stores the informations regarding versions
Constant Summary collapse
- DEFAULT_NAME =
Name of the cache file
'cache.json'
- CACHE_LIFE =
Maximum duration after which the cache is considered outdated Currently set to 24h
60 * 60 * 24
- GLOBAL_CACHE_URL =
'https://dragonbox.github.io/unities/v1/versions.json'
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(path: nil, force_os: nil, force_refresh: false, offline: false, central_cache: false) ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize(path: nil, force_os: nil, force_refresh: false, offline: false, central_cache: false) ⇒ Cache
Returns a new instance of Cache.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/u3d/cache.rb', line 58 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. Utils.ensure_dir(@path) file_path = File.(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 |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
50 51 52 |
# File 'lib/u3d/cache.rb', line 50 def path @path end |
Class Method Details
.default_os_path ⇒ Object
75 76 77 |
# File 'lib/u3d/cache.rb', line 75 def self.default_os_path U3dCore::Helper.data_path end |
Instance Method Details
#[](key) ⇒ Object
52 53 54 55 56 |
# File 'lib/u3d/cache.rb', line 52 def [](key) return nil if @cache[key].nil? @cache[key] end |