AssetCache

Every asset you download lands here once, so reading it again makes no request.

You reach it as AssetService.Cache. It is one folder: a raw file per asset id, its ending named by what the bytes are, plus an index, and deleting any of it is safe, since it refills. MaxBytes caps the size by dropping the least recently used downloads. Local assets, kept with PutLocalAsync, live beside them and are never evicted or cleared. Two programs should never share one cache folder at once.

ShotInstancenot creatableRoblox

Use AssetService.Cache.

Properties

NameTypeDefaultDescription
FolderstringThe folder of raw downloads, one file per asset id plus an index; deleting any of it is safe, since it refills.
MaxBytesnumber?The most bytes downloads may take, nil for no limit; past it the least recently used go, never the one just downloaded.

Methods

NameArgumentsReturnsDescription
HasAsync
yields
(assetId: number)booleanWhether a download of the asset is in the cache now; false again after RemoveAsync, ClearAsync or an eviction.
GetAsync
yields
(assetId: number)(buffer?, string?)Waits for the bytes Roblox served, from the cache or else downloaded; two callers of one missing id share a single download.
GetPathAsync
yields
(assetId: number)(string?, string?)Waits for the cached file's path, downloading it first when missing; the file's ending says what the bytes are, such as .png.
RemoveAsync
yields
(assetId: number)(boolean, string?)Forgets the asset so the next read fetches its current version; removing an id that was never cached is fine.
ClearAsync
yields
()(boolean, string?)Removes every download; local assets stay.
SizeAsync
yields
()numberThe total bytes of every download in the cache; local assets aren't counted.
PutLocalAsync
yields
(content: buffer | string, extension: string)(string?, string?)Keeps content as a local asset and gives its localasset://<id>.<ext> id; the same bytes get the same id, never evicted or cleared.
ReadLocalAsync
yields
(id: string)(buffer?, string?)The bytes of a local asset by its localasset:// id, or the part after it; a missing one gives nil and why.
From ShotInstance 33