ptarjan / node-cache

A simple in-memory cache for nodejs
BSD 2-Clause "Simplified" License
1.59k stars 214 forks source link

Is this a bug about `this.del` function #96

Open songjinzhong opened 6 years ago

songjinzhong commented 6 years ago

https://github.com/ptarjan/node-cache/blob/27a1eeec18660b45d39cc5daf44d9647e696e48b/index.js#L53

When a record is about to expire, we take the initiative to delete it. And due to the running time of the program, oldRecord.expire < Date.now() === true, so the record will not be deleted.

AsynchronousToddler commented 6 years ago

Yeah, that seems silly to me. If you’re manually invoking a delete function then jr shouldn’t matter wether or not the record is expiring. It should delete it regardless

IvanAdmaers commented 2 years ago

I think it’s an interesting idea to have a method that won't delete a key if it isn't expired. But it’s really strange when you don't have an opportunity to delete something that doesn’t expired. In my similar package memory-cache-pro you can use the ‘delete(key)’ method to delete something and it doesn’t check the key expiration time