Add ability to delete cache
Cesium caches all 3D tiles on local app storage without ever deleting them, this means that it adds up from 0 all the way to 10gb quite quickly.
My script:
void OnApplicationQuit()
{
Caching.ClearCache();
Directory.Delete(Application.temporaryCachePath, true);
//-
string cacheDir = Application.temporaryCachePath;
string[] filesToDelete =
{
"cesium-request-cache.sqlite",
"cesium-request-cache.sqlite-shm",
"cesium-request-cache.sqlite-wal"
};
// Loop through the files and delete them
foreach (string fileName in filesToDelete)
{
string filePath = Path.Combine(cacheDir, fileName);
// Check if the file exists before attempting to delete it
if (File.Exists(filePath))
{
// Delete the file
File.Delete(filePath);
}
}
}
Doesn't clear up that occupied space.
It's true that there's currently no way to clear the cache (though it can be done from C++ code). But you can control the size of it by setting the maxItems property on CesiumRuntimeSettings:
https://cesium.com/learn/cesium-unity/ref-doc/classCesiumForUnity_1_1CesiumRuntimeSettings.html#a5e8479d314bc290cf06312a7d932b4ca
But you can control the size of it by setting the
maxItemsproperty onCesiumRuntimeSettings
Yeah! I've documented myself before making this post, but unfortunately not knowing how much these properties represent in storage memory space makes them useless for me.
I don't want to risk setting them low and then have a more limited in-app 3D cache without being able to tell.
So I just set them to
maxItems = 7500, requestsPerCachePrune = 6144.
My in-app 3D cache shouldn't use more than 1gb of RAM at runtime, therefore I don't need more than an additional 1gb spent on storage.
Could you help me approximate how much these properties reflect in storage size, or at least let me know a better combination of these two properties for my use case?
Thanks!
Each "item" is a Tile. So the size of 7500 items will vary significantly based on how the tileset is constructed. Here's the enhancement request to allow the cache size to be specified in bytes instead: https://github.com/CesiumGS/cesium-native/issues/671
This isn't currently on our near-term roadmap, but we'd welcome a community pull request for it.
I'm using Google's 3D Tiles in case I forgot to mention, but thanks..
You can query your own database using the sqlite3 command-line utility (download here: https://sqlite.org/download.html).
select min(length(responseData)), max(length(responseData)), avg(length(responseData)) from CacheItemTable;
That will give you the minimum, maximum, and average size of the objects in your cache, in bytes.