简体   繁体   中英

Create a cache file which is automatically deleted when partition is nearly full in libc (all file systems) or ext4?

When writing software which needs to cache data on disk, is there a way in libc, or a way which is specific to a certain file system (such as ext4), to create a file and flag it as suitable to be deleted automatically (by the kernel) if the partition becomes almost full?

There's something similar for memory pages: madvise(…, MADV_FREE) .

Some systems achieve this by writing a daemon which monitors the partition fullness, and which manually deletes certain pre-determined paths once it exceeds a certain fill level. I'd like to avoid this if possible, as it's not very scalable: each application would have to notify the daemon of new cache paths as they are created, which may be frequently. If this were in-kernel, a single flag could be held on each inode indicating whether it's a cache file.

Having a standardised daemon for this would be acceptable as well. At the moment it seems like different major systems integrators all invent their own.

You can use crontab job, and look for specific file extension and delete it. You can even filter based on time and leave the files created in last n minutes. If you are ok with this, let me know, I will add more details here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM