Welcome Guest, Not a member yet? Register   Sign In
Input on caching methods?
#1

I'm starting to work on caching for my application and I'd appreciate some input.

Some facts about my site (www.danceminder.com):

1. It's fairly dynamic but doesn't change that frequently.  Yet. Once I allow more users editing access I expect that to change.
2. There are two main views for dances.  Crib or Full which completely changes the look of the page.  Even though the look changes, the underlying structure doesn't.  There's a Dance, one or more Figures and for each Figure there are one or more Movements.
3. Every element of a dance is time-stamped so I know exactly when it was last changed.
4. The pages are presented slightly differently depending on who is viewing the page.  If it's a non-logged in user they don't get all the information and/or menu links change.  If they're an editor or admin, the menus change even more. So I may or may not want to cache the menus.  Or I might.

I'm currently thinking that I can get away with caching Dance/Figure/Movement output independently.

I'm also thinking that I might need a cache-key table in the database so I can keep track of when a cache entry was last updated and use very long expire times so that rather than the cache expiring based on time, I regenerate it based only on need.

I may also need to trigger a cache update if view or css code changes.  I don't want to invalidate the entire cache but that may be the simplest method for now.

Any particular thoughts or feedback?  I haven't implemented caching in a PHP app before so any info is welcome.
Reply
#2

(04-05-2016, 10:29 AM)michaelh99 Wrote: I'm starting to work on caching for my application and I'd appreciate some input.

Some facts about my site (www.danceminder.com):

1. It's fairly dynamic but doesn't change that frequently.  Yet. Once I allow more users editing access I expect that to change.
2. There are two main views for dances.  Crib or Full which completely changes the look of the page.  Even though the look changes, the underlying structure doesn't.  There's a Dance, one or more Figures and for each Figure there are one or more Movements.
3. Every element of a dance is time-stamped so I know exactly when it was last changed.
4. The pages are presented slightly differently depending on who is viewing the page.  If it's a non-logged in user they don't get all the information and/or menu links change.  If they're an editor or admin, the menus change even more. So I may or may not want to cache the menus.  Or I might.

I'm currently thinking that I can get away with caching Dance/Figure/Movement output independently.

I'm also thinking that I might need a cache-key table in the database so I can keep track of when a cache entry was last updated and use very long expire times so that rather than the cache expiring based on time, I regenerate it based only on need.

I may also need to trigger a cache update if view or css code changes.  I don't want to invalidate the entire cache but that may be the simplest method for now.

Any particular thoughts or feedback?  I haven't implemented caching in a PHP app before so any info is welcome.

Are you trying to cache the views or the data?
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#3

I'm thinking at the moment of caching the view information. Not the whole page but probably in chunks divided up between the Dance and Figures (maybe as granular as the Movements, but probably not).
Reply
#4

If you're trying to cache for performance, usually DB calls are the slowest part of any application, so caching the data will allow you to see the biggest improvement.

So I'd recommend caching the data. You can use file based caching (slowest), or some other form of caching like Memcached or Redis (Very fast). CI has drivers for both of them and all you'll have to do is run a memcached or redis server and connect them accordingly.

Are you experiencing a lot of page hits or serious performance issues? If you are only getting a couple hundred page hits an hour and your sql queries are optimized, there usually isn't much need at all for caching.
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#5

Thanks for the input.

It strikes me that by caching the view data I'm also caching the db results since that's how I build the view data. so in essence I should see the gains you mention as well as gains by not regenerating the views.

Am I off-base?
Reply
#6

caching works really well for concurrent users - or a bunch of people hitting the same page (and the database) at the same time. so even if your page content changes constantly - if you set the cache time for just 5 minutes - you are still limiting the database calls to once every 5 minutes for that page, versus hundreds of calls per second if its very popular. even a cache time of 1 minute would still greatly speed up the response time.

codeigniter by default is going to cache the entire page. so if your content is changing every few seconds then you might need to cache different parts of the page. otherwise its a matter of setting the time appropriately. i'm a huge fan of codeigniter caching because its so easy, and it really makes a difference in the response time of the page.
Reply
#7

Thanks.

I think I probably don't want to go the "cache the whole page" route since CI doesn't have enough knowledge about when or how the page changes. There are also some user-specific elements to the page and I don't want users that aren't logged in to have access to admin controls :-)

Having said that though, I think as a first step I'll work on adding some stats so I can see more clearly the site usage patterns. It might be that most of the users are non-members in which case there's probably a gross level of caching that would help in most cases. I can get more finer-grained caching once I know better where the need is.
Reply
#8

Make sure you understand the difference between caching the view and caching the data. Once you have the data, php generates views very quickly. You'd have to have remarkable traffic for the view generation to be your bottleneck. Caching your data that comes from a database / api can grant you significant gains though.

I'd recommend checking through the profiler what your biggest bottleneck is and then start tackling it from there. I'd guess that your database calls are what is costing the most, so start off by caching those accordingly. Eventually, if you have optimized everything else and you still need performance, you may want to look at something else for your view generation like a front end framework.
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#9

Thanks for the input. I've added xdebug to my server to get more detailed information and I do plan on optimizing my queries to best of my current ability. I'll also experiment with the query caching and see what gains can be made.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB