Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENOENT: no such file or directory on the odd occasion when cache retrieves up around 50 per second #28

Open
phillip-odam opened this issue Jun 14, 2021 · 0 comments

Comments

@phillip-odam
Copy link

phillip-odam commented Jun 14, 2021

The following error was observed when diskCache.get() was called at a frequency of around 50 per second. At lower rates like 5 to 10 per second we never observed the error.

[Error: ENOENT: no such file or directory, open '/tmp/diskcache/cache_99e4ffff-6392-45b1-ba69-21786819c784.dat'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/tmp/diskcache/cache_99e4ffff-6392-45b1-ba69-21786819c784.dat'
}

Following cache-manager code used in an AWS Lambda.

"use strict";

const cacheManager = require("cache-manager");
const fsStore = require("cache-manager-fs");

const diskCache = cacheManager.caching({
   store: fsStore,
   options: {
      ttl: 300,
      maxsize: 10485760,
      path: "/tmp/diskcache",
      preventfill: true
   }
});

The following code was being used when the error above was encountered.

   diskCache.get("SOME KEY FOR CACHE", function (err, result) {
      if (err) {
         console.error({ error: err, result: result });
      } else if (result) {
         // do something based on result from cache
      } else {
         var args = {
            "Bucket": "SOME AWS S3 BUCKET",
            "Key": "SOME AWS S3 KEY"
         };

         s3.getObject(args, function (err, data) {
            if (err) {
               console.error({ error: err, data: data });
            } else {
               var json = data.Body.toString("ascii");
               diskCache.set("SOME KEY FOR CACHE", json);
               // do something based on result from cache
            }
         });
      }
   });

Changing to the following will address and work-around the odd occurrence of the error, however we figured we'd raise this incase we're not using cache-manager correctly.

   diskCache.get("SOME KEY FOR CACHE", function (err, result) {
      if (result) {
         // do something based on result from cache
      } else {
         if (err) {
            console.error({ error: err, result: result });
         }
         var args = {
            "Bucket": "SOME AWS S3 BUCKET",
            "Key": "SOME AWS S3 KEY"
         };

         s3.getObject(args, function (err, data) {
            if (err) {
               console.error({ error: err, data: data });
            } else {
               var json = data.Body.toString("ascii");
               diskCache.set("SOME KEY FOR CACHE", json);
               // do something based on result from cache
            }
         });
      }
   });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant