Vixen
02b45cc4
csharp
public sealed class BundleCache

Downloaded bundles, kept on the device and keyed by content.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Keyed by hash, not by name. A bundle called dlc-pack-2 that gets rebuilt is a different file with the same name, and a cache that trusted the name would serve the old one forever. Filing it under its content hash means a rebuilt bundle is simply a cache miss, and means two catalog versions that share an unchanged bundle share the download.

Downloads resume. Bytes go to <hash>.part as they arrive, and a fetch that finds one asks the server to continue from where it stopped. This is not an optimisation on a phone: a 400 MB pack over a connection that drops every few minutes never finishes without it.

Nothing is committed unverified. A completed download has to be the length the catalog says and hash to the CRC the catalog says before it is moved to <hash>.bundle; anything else is deleted rather than kept and retried against. The CRC is the catalog's, so it catches a corrupted transfer and a server serving something else entirely at that URL.

A cache hit is checked for length, not re-hashed. Length is a metadata read and catches the one failure a committed file can plausibly have — being truncated by a crash mid-commit or by the OS reclaiming space. Re-hashing every cached bundle at every load would put a full pass over hundreds of megabytes in front of a loading screen to catch bit rot, which is not where that check belongs. VerifyAsync is there for a caller who does want it.

Fields and properties (2)

  • public VirtualPath Root

    Where cached bundles are kept.

  • public int BufferSize

    How many bytes to move at a time.

Methods (10)

  • public BundleCache(VirtualFileSystem files, VirtualPath root, IContentTransport transport)

    Sets up a cache.

  • public VirtualPath PathOf(CatalogBundle bundle)

    Where a bundle is cached once it is complete.

  • public VirtualPath PartialPathOf(CatalogBundle bundle)

    Where a bundle's bytes accumulate while it is being fetched.

  • public bool IsCached(CatalogBundle bundle)

    Whether a bundle is cached and the right length.

  • public long ReceivedSoFar(CatalogBundle bundle)

    How many bytes of a bundle a previous attempt already fetched.

  • public Task<VirtualPath> EnsureAsync(CatalogBundle bundle, IProgress<BundleProgress>? progress = null, CancellationToken cancellationToken = default(CancellationToken))

    Makes sure a bundle is on the device, fetching it if it is not.

  • public ValueTask<bool> VerifyAsync(CatalogBundle bundle, CancellationToken cancellationToken = default(CancellationToken))

    Re-hashes a cached bundle and checks it against the catalog.

  • public bool Evict(CatalogBundle bundle)

    Deletes a bundle's cached copy and anything partial.

  • public int Clear()

    Deletes everything in the cache directory.

  • public long TotalSize()

    How much of the device the cache is using, complete and partial together.

Used by (8)

  • ProgramAddressablesRemote
  • BundleCacheTestsVixen.Assets.Tests
  • CacheWorldVixen.Assets.Tests
  • ContentMountVixen.App.Hosting
  • RemoteBundleSourceVixen.Assets
  • UpdateWorldVixen.Assets.Tests
  • VixenApplicationVixen.App.Hosting
  • RemoteContentMountTestsVixen.App.Tests