cache-manager
cache-manager copied to clipboard
Support cache strategy without checking timestamps
Prettier uses the file-entry-cache package, and when running prettier with a cache in CI, since modified timestamps are not preserved on a clone, it always reports a cache miss. I would love a way to only use the hash to detect changes (i.e. ignore mtime). Is that possible? Perhaps a similar option like useModifiedTime that defaults to true?
https://github.com/jaredwray/cacheable/blob/a95f7f7f8c2dafcd78fee6a310874a6b03ed974b/packages/file-entry-cache/src/index.ts#L299-L305
@reteps - thanks for sending this over. I like that approach and was wondering if you have any tests that I can reference to validate this when I get this feature added.
I only mentioned this in the context of prettier -- you could update the flag in prettier's config locally, and check that the files aren't re-checked by prettier after you run touch across all of them.
@reteps - I am going to add this in but you will need to make the change to not use the helper functions create or createFromFile as we will need to introduce a breaking change and plan to do that in the next month.
To do this just use the FileEntryCache class like so:
import {FileEntryCache} from 'file-entry-cache';
const fileEntryCache = new FileEntryCache({useModifiedTime: false});
or you can now do it on getFileDescriptor such as:
import {FileEntryCache} from 'file-entry-cache';
const fileEntryCache = new FileEntryCache();
const result = fileEntryCache.getFileDescriptor('foo.txt', {useModifiedTime: false});
In the next month we will be adding in a big update allowing you to use relative paths and will make the breaking change then on the helper functions.