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'.freeze 
- 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'.freeze 
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.
| 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | # 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. 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.
| 48 49 50 | # File 'lib/u3d/cache.rb', line 48 def path @path end | 
Class Method Details
Instance Method Details
#[](key) ⇒ Object
| 50 51 52 53 | # File 'lib/u3d/cache.rb', line 50 def [](key) return nil if @cache[key].nil? @cache[key] end |