Sha256: 298830a18aa56bccdbfa6a98ceee3fc891fa06d5bdab0483e10cbf0f422ae609

Contents?: true

Size: 1016 Bytes

Versions: 56

Compression:

Stored size: 1016 Bytes

Contents

# frozen_string_literal: true

module Avm
  module Launcher
    module Instances
      module Base
        module Cache
          def cache_path(subpath)
            File.join(cache_root, subpath)
          end

          def cache_key(key, &block)
            v = cache_key_get(key)
            return v if v.present? || block.nil?

            v = yield
            cache_key_write(key, v)
            v
          end

          private

          def cache_key_get(key)
            File.file?(cache_key_path(key)) ? File.read(cache_key_path(key)) : nil
          end

          def cache_key_write(key, value)
            FileUtils.mkdir_p(File.dirname(cache_key_path(key)))
            File.write(cache_key_path(key), value)
          end

          def cache_key_path(key)
            File.join(cache_root, 'keys', key.parameterize)
          end

          def cache_root
            File.join(::EacLauncher::Context.current.cache_root, name.parameterize)
          end
        end
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
avm-tools-0.99.0 lib/avm/launcher/instances/base/cache.rb
avm-tools-0.98.0 lib/avm/launcher/instances/base/cache.rb
avm-tools-0.97.0 lib/avm/launcher/instances/base/cache.rb
avm-tools-0.96.0 lib/avm/launcher/instances/base/cache.rb
avm-tools-0.95.0 lib/avm/launcher/instances/base/cache.rb
avm-tools-0.94.3 lib/avm/launcher/instances/base/cache.rb
avm-tools-0.94.2 lib/avm/launcher/instances/base/cache.rb
avm-tools-0.94.1 lib/avm/launcher/instances/base/cache.rb
avm-tools-0.94.0 lib/avm/launcher/instances/base/cache.rb
avm-tools-0.93.0 lib/avm/launcher/instances/base/cache.rb
avm-tools-0.92.0 lib/avm/launcher/instances/base/cache.rb
avm-tools-0.91.0 lib/avm/launcher/instances/base/cache.rb
avm-tools-0.90.0 lib/avm/launcher/instances/base/cache.rb
avm-tools-0.89.0 lib/avm/launcher/instances/base/cache.rb
avm-tools-0.88.0 lib/avm/launcher/instances/base/cache.rb
avm-tools-0.87.1 lib/avm/launcher/instances/base/cache.rb
avm-tools-0.87.0 lib/avm/launcher/instances/base/cache.rb
avm-tools-0.86.0 lib/avm/launcher/instances/base/cache.rb
avm-tools-0.85.1 lib/avm/launcher/instances/base/cache.rb
avm-tools-0.85.0 lib/avm/launcher/instances/base/cache.rb