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

Delete data on expiration in memory backend #32

Closed
fdegiuli opened this issue Jun 28, 2016 · 2 comments
Closed

Delete data on expiration in memory backend #32

fdegiuli opened this issue Jun 28, 2016 · 2 comments

Comments

@fdegiuli
Copy link
Contributor

fdegiuli commented Jun 28, 2016

The memory backend lazily deletes expired values on get:

MemoryBackend.prototype.get = function get(key) {
  var wrappedValue = this.cache[key] || null;
  if (util.isExpired(wrappedValue && wrappedValue.e)) {
    wrappedValue = null;
    delete this.cache[key];
  }
  return Bluebird.resolve(wrappedValue ? wrappedValue.d : null);
};

This causes a memory leak if the data isn't accessed again, which is epecially a problem with versioned data.

Is there any interest on your end in deleting the data via timeout?
E.g.:

MemoryBackend.prototype.set = function set(key, value, options) {
  this.cache[key] = {
    d: value,
  };
  if (options.expire) {
    setTimeout(this.unset.bind(this, key), options.expire * 1000);
  }
  return Bluebird.resolve(value);
};

I know you probably do the lazy expire for a reason. So if you're not into it, would you take a look at #31 so I we can do it from the outside?

@jkrems
Copy link
Contributor

jkrems commented Aug 21, 2016

I think the manual deletion is more in line with what we had for the memory backend. Maybe we should also clarify in the docs that the memory backend isn't well-suited for general purpose caching in production. E.g. even without active pruning of old values it might run out of memory if you try to use it as anything as a "better" Map since there's no cache eviction etc..

@jkrems jkrems closed this as completed Aug 21, 2016
@Juraj-Masiar
Copy link

The docs should have been indeed updated. I was tracking down a slow memory leak for past several days and after checking the source code here, I see the expired items are never removed :(.

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

3 participants