wavly / shawty

Tool for shortening long URLs
MIT License
5 stars 0 forks source link

Store `access_count` and `last_access` in a cache #36

Closed Hamza12700 closed 1 month ago

Hamza12700 commented 2 months ago

The problem

The server only caches the results for the code (the key) and original_url (the value).

But when the request gets redirected to the original URL even tho it's grabbing the value from the cache (if it's cached) it still makes a call to the database updating the access_count and the last_access values. That's a problem because If the server gets a lot of requests for a redirect, that means a lot of calls to the database.

The solution

To prevent this, store and update the values access_count and last_access in memcache when redirecting the request and only make a call to the database when the user visits the stats page; write the value stored in memcache to the database.