Skip to content

Commit a46da87

Browse files
committed
feature: cache: check mtime when change do not work
1 parent 7368c1f commit a46da87

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

packages/cli-cache/lib/cache.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ const setInfo = ({fileCache, getOptionsHash}) => (name, places, options) => {
104104

105105
meta.data.optionsHash = getOptionsHash(options);
106106
meta.data.places = places;
107+
meta.data.mtime = meta.mtime;
107108
};
108109

109110
const canUseCache = ({fileCache, getOptionsHash}) => (name, options) => {
@@ -122,6 +123,9 @@ const canUseCache = ({fileCache, getOptionsHash}) => (name, options) => {
122123
if (!data)
123124
return false;
124125

126+
if (meta.mtime !== data.mtime)
127+
return false;
128+
125129
const {places, optionsHash} = data;
126130

127131
if (optionsHash !== getOptionsHash(options))

packages/cli-cache/lib/cache.spec.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,53 @@ test('putout: cli: cache: enabled: setInfo: not set', async (t) => {
254254
t.end();
255255
});
256256

257+
test('putout: cli: cache: enabled: canUseCache: mtime changed', async (t) => {
258+
const data = {
259+
mtime: 123,
260+
optionsHash: 'hello',
261+
places: ['world'],
262+
};
263+
264+
const meta = {
265+
data,
266+
mtime: 1,
267+
};
268+
269+
const changed = false;
270+
271+
const getFileDescriptor = stub().returns({
272+
meta,
273+
changed,
274+
});
275+
276+
const createFromFile = stub().returns({
277+
getFileDescriptor,
278+
reconcile: stub(),
279+
});
280+
281+
const fileEntryCache = {
282+
createFromFile,
283+
};
284+
285+
mockRequire('./is-changed', stub());
286+
mockRequire('file-entry-cache', fileEntryCache);
287+
const {createCache} = reRequire('./cache');
288+
289+
const fileCache = await createCache({
290+
cache: true,
291+
files: [],
292+
});
293+
294+
const name = 'hello';
295+
const options = {};
296+
297+
const result = fileCache.canUseCache(name, options);
298+
stopAll();
299+
300+
t.notOk(result);
301+
t.end();
302+
});
303+
257304
test('putout: cli: cache: enabled: canUseCache: changed', async (t) => {
258305
const meta = {
259306
optionsHash: 'hello',
@@ -372,6 +419,7 @@ test('putout: cli: cache: enabled: canUseCache: options changed', async (t) => {
372419
optionsHash: 'hello',
373420
places: ['world'],
374421
};
422+
375423
const meta = {
376424
data,
377425
};

0 commit comments

Comments
 (0)