lib/u3d/cache.rb in u3d-1.0.1 vs lib/u3d/cache.rb in u3d-1.0.2
- old
+ new
@@ -49,26 +49,31 @@
def [](key)
return nil if @cache[key].nil?
@cache[key]
end
- def initialize(path: nil, force_os: nil, force_refresh: false)
+ def initialize(path: nil, force_os: nil, force_refresh: false, offline: false)
+ raise "Cache: cannot specify both offline and force_refresh" if offline && force_refresh
@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)
+ 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) if need_update || force_refresh
end
private #-------------------------------------------------------------------
# Checks if the cache needs updating
def check_for_update(file_path, os)
need_update = false
- data = nil
+ data = {}
if !File.file?(file_path)
need_update = true
else
begin
File.open(file_path, 'r') do |f|