Reputation: 15
Currently i m using shared hosting domain for my site .But we have currently near about 11,00,000 rows in one of the tables.So its taking a lot of time to load the webpage.So we want to implement the database caching techniques like APC or memcache for our site.But in shared domain we dont have those facilities available,we have only eaccelerator.But eaccelerator does not cache db calls,If i m not wrong.So considering all these points we want to move to VPS and in this case.which database caching technique we need to use APC or memcache to decrease the page load time...Please guide on VPS and better caching technique of two
Upvotes: 0
Views: 305
Reputation: 522085
From your comment I take it you're doing a LIKE %..%
query and want to paginate the result. First of all, investigate whether FULLTEXT indices are an option for you, as they should perform better. If that's not an option, you can add a simple cache like so:
..?search=foobar
, then "foobar" is the id of the result set. Keep that in all your links, e.g. ..?search=foobar&page=2
.sha1($query)
, or maybe sha1(strtolower($query))
.serialize
the data and store it in the file.unserialize
it, display the portion of the array corresponding to the requested page.if (rand(0, 100) == 1) ..
, which will run the cleanup job every 100 queries on average. Strike a balance between server load and data freshness. Cache invalidation is a topic whole books can be written about, BTW.That's a simple poor man's cache implementation. It's not great, but if you have absolutely nothing else to work with, it's better than running slow queries over and over.
Upvotes: 0
Reputation: 1129
I had a task where i needed to fetch rows from a database table that had more than 100.000 record. it was a scrollable page. So what i did was to fetch the first 50 records and cache the next 50 in the first call. and on scroll down events i wrote an ajax request to check if the data is available in cache; if not i fetched it from the database and also cached the next 50. It worked pretty well and solved the inconvenient load time.
if you have a similar scenario you might benefit from this approach.
ps: I used memcache.
Upvotes: 0
Reputation: 918
we have similar website and we use APC
APC will cache the opcode as well the html that is generated. This helps to avoid unrequired hits to the page
you should also enable caching on mysql to cache results of your query
Upvotes: 0
Reputation: 3663
APC is Alternative PHP Cache and works only with PHP. Whereas Memcahced will work independently with any language.
Upvotes: -1