Skip to content

Commit 4a7b14e

Browse files
committed
Touch file when reading it #6
1 parent bf875ad commit 4a7b14e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ function decodeAssetCacheName(encodedString) {
5454
return decodedFileName.split(":");
5555
}
5656

57+
function touch(path) {
58+
const time = new Date();
59+
try {
60+
fs.utimesSync(path, time, time);
61+
} catch (err) {
62+
fs.closeSync(fs.openSync(path, "w"));
63+
}
64+
}
65+
5766
const middleWare = (module.exports = function(options) {
5867
return async function(req, res, next) {
5968
options = options || {};
@@ -78,6 +87,9 @@ const middleWare = (module.exports = function(options) {
7887
if (fs.existsSync(assetCachePath)) {
7988
const firstFile = fs.readdirSync(assetCachePath)[0];
8089

90+
// touch file for LRU eviction
91+
touch(`${assetCachePath}/${firstFile}`);
92+
8193
const [contentType, contentLength] = middleWare.decodeAssetCacheName(
8294
firstFile
8395
);

0 commit comments

Comments
 (0)