So I have a PHP CodeIgniter webapp and am trying to decide whether to incorporate caching.
Please bear with me on this one, since I’ll happily admit I don’t fully understand caching!
-
So the first user loads up a page of user submitted-content. It takes 0.8 seconds (processing) to load it ‘slow’. The next user then loads up that same page, it takes 0.1 seconds to load it ‘fast’ from cache.
-
The third user loads it up, also taking 0.1 seconds execution time. This user decides to comment on the page.
-
The fourth user loads it up 2 minutes later but doesn’t see the third user’s comment, because there’s still another 50 minutes left before the cache expires
What do you do in this situation? Is it worth incorporating caching on pages like this?
The reason I’d like to use caching is because I ran some tests. Without caching, my page took an average of 0.7864 seconds execution time. With caching, it took an average of 0.0138 seconds. That’s an improvement of 5599%!
I understand it’s still only a matter of milliseconds, but even so…
Jack
You want a better cache.
Typically, you should never reach your cache’s timeout. Instead, some user-driven action will invalidate the cache.
So if you have a scenario like this:
I’m not a CodeIgniter guy, so I’m not sure what that framework will do for you, but the above is generally what should happen. Your application should have enough smarts built-in to invalidate cache entries when data gets written that requires cache invalidation.