Class: Bsdkrun::Cache
- Inherits:
-
Object
- Object
- Bsdkrun::Cache
- Defined in:
- lib/bsdkrun/cache.rb
Overview
Save and restore guest directories under a key, reached as Sandbox#cache.
Entries are keyed, so a rebuild can pick up where the last one left off:
hit = sbx.cache.restore(key: key, restore_keys: ["deps-"])
unless hit.restored
sbx.exec(["npm", "ci"])
sbx.cache.save("/app/node_modules", key: key)
end
Where entries live — host disk or S3 — is host configuration, not an SDK
concern: set BSDKRUN_CACHE_BACKEND / BSDKRUN_CACHE_S3_*, or write
~/.config/bsdkrun/cache.toml.
Instance Method Summary collapse
-
#initialize(id) ⇒ Cache
constructor
A new instance of Cache.
-
#restore(key:, path: nil, restore_keys: []) ⇒ RestoreResult
Restore a stored tree.
-
#save(path, key:, compression: "gzip", force: false) ⇒ CacheEntry
Archive the guest directory at
pathunderkey.
Constructor Details
#initialize(id) ⇒ Cache
Returns a new instance of Cache.
41 42 43 |
# File 'lib/bsdkrun/cache.rb', line 41 def initialize(id) @id = id end |
Instance Method Details
#restore(key:, path: nil, restore_keys: []) ⇒ RestoreResult
Restore a stored tree.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/bsdkrun/cache.rb', line 65 def restore(key:, path: nil, restore_keys: []) target = path ? "#{@id}:#{path}" : @id args = ["cache", "restore", target, "--key", key, "--json"] args += ["--restore-keys", *restore_keys] unless restore_keys.empty? row = json(args, "bsdkrun cache restore") RestoreResult.new( restored: !!row["restored"], requested_key: row["requested_key"].to_s, key: row["key"], path: row["path"], size: row["size"], compression: row["compression"], created: row["created"] ) end |
#save(path, key:, compression: "gzip", force: false) ⇒ CacheEntry
Archive the guest directory at path under key.
52 53 54 55 56 57 |
# File 'lib/bsdkrun/cache.rb', line 52 def save(path, key:, compression: "gzip", force: false) args = ["cache", "save", "#{@id}:#{path}", "--key", key, "--json"] args += ["--compression", compression] unless compression == "gzip" args << "--force" if force CacheEntry.from(json(args, "bsdkrun cache save")) end |