philcockfield / file-system-cache

A super-fast, promise based cache that reads and writes to the file-system.
MIT License
51 stars 14 forks source link

Feature Request: Custom "hash" function #40

Open codemariner opened 1 year ago

codemariner commented 1 year ago

I'm using file-system-cache to help store fixture data for tests. I'd like to be able to easily read the file system and see which file is for what data. Perhaps something like this:

interface HashFn {
    (...values:any[]):string
}

type FileSystemCacheOptions = {
    basePath?: string;
    ns?: any;
    ttl?: number;
    hash?: HashAlgorithm | HashFn;
    extension?: string;
};

//...

const cache = Cache({
    basePath: path.join(__dirname, 'cache'),
    ns: 'test-fixtures',
    hash: (...values:any[]) {
        return customizeFilename(values);
    }
})

for now, I'm just monkey patching the util#hash function.