brentwalther 0 Share Posted July 14, 2016 It's unneccesary to flush the entire cache every 10 minutes. What if one of the prices was only looked up one minute ago? It'd be better to add an updatedAt field to the result and then users will know how old it is and your price updater can simply loop through the map periodically and refresh (or remove) prices that are more than 10 minutes old. Link to comment Share on other sites More sharing options...
Calculus 30 Author Share Posted July 14, 2016 It's unneccesary to flush the entire cache every 10 minutes. What if one of the prices was only looked up one minute ago? It'd be better to add an updatedAt field to the result and then users will know how old it is and your price updater can simply loop through the map periodically and refresh (or remove) prices that are more than 10 minutes old. Not really m8, the entire point of this was to "Auto-Update" (check the title). It does exactly what it says it does, and won't update the prices until something is re-queued. I don't think you understand the concept of the code, or didn't read it fully, so here's an example of how it works: Example: I lookup an item. I lookup the same item 9 minutes later The item is not re-updated The elapsed time has now passed 10 minutes Nothing happens, it doesn't matter. No need to waste CPU/network time I lookup the same item 18 minutes later The item is now refreshed. EDIT: If you don't queue a new item, it won't be refreshed. It also doesn't refresh the entire cache, it simply flushes them, which means that the NEXT time they're queued, it will be updated. This code is pretty damn efficient. Also, if you want to add your own "updatedAt" feature or whatever, go for it. This is just a snippet for the public to use/expand on, not something you're paying for, or I need to keep updated. Link to comment Share on other sites More sharing options...
brentwalther 0 Share Posted July 14, 2016 Not really m8, the entire point of this was to "Auto-Update" (check the title). It does exactly what it says it does, and won't update the prices until something is re-queued. I don't think you understand the concept of the code, or didn't read it fully, so here's an example of how it works: Example: I lookup an item. I lookup the same item 9 minutes later The item is not re-updated The elapsed time has now passed 10 minutes Nothing happens, it doesn't matter. No need to waste CPU/network time I lookup the same item 18 minutes later The item is now refreshed. EDIT: If you don't queue a new item, it won't be refreshed. It also doesn't refresh the entire cache, it simply flushes them, which means that the NEXT time they're queued, it will be updated. This code is pretty damn efficient. Also, if you want to add your own "updatedAt" feature or whatever, go for it. This is just a snippet for the public to use/expand on, not something you're paying for, or I need to keep updated. I understand how it works, I was suggesting something like this to avoid completely invalidating the cache every 10 minutes: See this diff: https://www.diffchecker.com/hw6upmhe Link to comment Share on other sites More sharing options...
Calculus 30 Author Share Posted July 14, 2016 I understand how it works, I was suggesting something like this to avoid completely invalidating the cache every 10 minutes: See this diff: https://www.diffchecker.com/hw6upmhe I like it! Link to comment Share on other sites More sharing options...
xpt 0 Share Posted June 26, 2020 Very nice guys! Will certainly use the version enhanced by @brentwalther. Thanks so much, I was looking for this. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.