Cachier is a fast C++ header only library that provides simple and efficient way to cache computed data for files.
Use Case
Suppose you're developing an audio editor application where you need to perform certain calculations on an audio file each time you open it for editing. This process can take a significant amount of time and resources. To optimize your application, you can use Cachier to store the computed data in cache and retrieve it later whenever you open the same file again.
With Cachier, you can rely on the cached data to be correct and up-to-date, without the need to re-calculate it each time the file is opened. This results in a more efficient and faster user experience for your audio editor application.
How it works
- Initialize Cachier with a
cache_path
, which is the directory where you want to store your cache. - Process or extract some data from a file. (ex: Amplitude data from a big audio file)
- Store the computed data to the cache using Cachier's addCache method.
- Cachier computes a
unique key
for the file using its properties, like thefile name
,size
,last modification time
, and the first 8 bytes of fileheader info
. - The computed data is saved to the provided
cache_path
as a file named using the unique key computed by Cachier. - Later on, retrieve the computed data for the same file by asking Cachier to find it in the cache.
- Cachier computes the key for the file using the same strategy as before.
- Cachier performs a lookup in the cache directory for the file named using the computed key and returns the data stored in it. Note that the cache entry becomes invalid if the file has been modified.
How to use