cesium-unity icon indicating copy to clipboard operation
cesium-unity copied to clipboard

Add ability to delete cache

Open electrum-bowie opened this issue 8 months ago • 5 comments

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.

electrum-bowie avatar Apr 25 '25 17:04 electrum-bowie

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

kring avatar May 06 '25 03:05 kring

But you can control the size of it by setting the maxItems property on CesiumRuntimeSettings

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!

electrum-bowie avatar May 06 '25 05:05 electrum-bowie

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.

kring avatar May 06 '25 06:05 kring

I'm using Google's 3D Tiles in case I forgot to mention, but thanks..

electrum-bowie avatar May 06 '25 08:05 electrum-bowie

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.

kring avatar May 06 '25 08:05 kring