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.
The problem
The server only caches the results for the
code
(the key) andoriginal_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 thelast_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
andlast_access
inmemcache
when redirecting the request and only make a call to the database when the user visits the stats page; write the value stored inmemcache
to the database.