Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to delete all files of a file-type from cache?

Discussion in 'WebGL' started by Good_Punk, Apr 15, 2021.

  1. Good_Punk

    Good_Punk

    Joined:
    Aug 6, 2014
    Posts:
    81
    Hi,
    I've implemented an image downloader that stores jpg/pngs in "Application.temporaryCachePath". Now I want the option to clear all downloaded images again (without clearing the whole cache for the website).

    I've tried "System.IO.Directory.GetFiles(@Application.temporaryCachePath, ".png")". That works when I run it in the editor but not in a browser. I assume this is the case because the files are not individually saved in the cache/indexdb?

    So how can I delete all images instead?

    Thanks
     
  2. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    376
    Not a solution per-se but just be mindful that the entire System.IO namespace won't work for web apps due to, as it says, being sandboxed into a browser and can't communicate directly with the OS.

    I believe what you need to do is to look at either managing the indexdb directly or setup a backend service that can read/write files on your web server.
     
  3. Good_Punk

    Good_Punk

    Joined:
    Aug 6, 2014
    Posts:
    81
    That's not true. I'm using System.IO to write and load files from cache and it works just fine. :)
     
  4. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    376
    Last edited: Apr 15, 2021