Welcome Guest, Not a member yet? Register   Sign In
Database cache expiration
#1

[eluser]girir[/eluser]
Has anyone written a library or modified the DB Cache library to make the result expire after a certain amount of time?

Thanks!
#2

[eluser]tonanbarbarian[/eluser]
I have not used the DB Cache yet, but just looked through the user guide for it and I think I would prefer to write something at the model level for caching rather than at the controller+method level.

If models are used correctly then you may actually have numerous controllers using the same model and each could be using the same method in the model to gather data.
By having the caching at the model level it would be easier to control because when you get the model to do an insert or update you would then be able to clear the cache from the model since the data has changed.

The only issue then would be if the model is gathering data from other tables, as it often has to do.

Another thought I once had (pre CI days) was writing a caching system that analysed the tables used in the query and stored the cache against the various tables. when any table was written to (insert, update or delete) the cache system would look through the cache for any cached data that contained the updated table and purge it.

And yet another idea was to have a session based cache system. This is really only an advantage for a site where the user stays on the site for quite a while and runs the same queries multiple times. The files are cached based on the users sessions and when the session expires the cache is deleted. This way the cached data is only as old as the users session, and next time they log in they will see the more up to date data.

Anyway I am sure this is not helping...

My advice would be to only cache certain queries not everything, so use the $this->db-cache_on and cache_off to switch and have the cache off by default.
Then some minimal code could be used to determine how old a cache is and delete it periodically, even something as simple as storing the last datetime the cache was cleared in a table and then using that to clear the data every hour




Theme © iAndrew 2016 - Forum software by © MyBB