when get a key and it is not there, I would return undefined or an error. -1 could also be the value. It reminds me to the time when we needed if (array.indexOf(needle)===-1);{...} and today we have array.includes.
It is very interesting how you are using the iterator from cache.keys().
also, it would be interesting to add a time-to-life, but that can be a good homework 😊
Full-Stack Software Engineer; using a background in Acting and Voice-Over to pursue a lifelong love of software and technology from an arts and humanities perspective.
Thanks for your feedback Tobias! I was wondering what the best return value would be for when a key wasn't found, you're definitely right about "undefined" or throwing an error being better than returning a string. I'll edit that part to make it a bit more clear.
Also a great suggestion to add a timed-life option, I'll start thinking about how to implement that!
when get a key and it is not there, I would return undefined or an error.
-1
could also be the value. It reminds me to the time when we neededif (array.indexOf(needle)===-1);{...}
and today we havearray.includes
.It is very interesting how you are using the
iterator
fromcache.keys()
.also, it would be interesting to add a time-to-life, but that can be a good homework 😊
Thanks for your feedback Tobias! I was wondering what the best return value would be for when a key wasn't found, you're definitely right about "undefined" or throwing an error being better than returning a string. I'll edit that part to make it a bit more clear.
Also a great suggestion to add a timed-life option, I'll start thinking about how to implement that!
Delegate the problem to the caller -- have them provide a value to return in the not-found case.