K
K
KOS_MOS2011-03-01 14:39:02
PHP
KOS_MOS, 2011-03-01 14:39:02

Caching pre-request data in PHP

Problem: About 200 requests of the same type are made to the database, but there are no identical ones, each time one parameter changes, so caching the result is not suitable here.

I know in advance the range of records to which the request is made, so this idea was born - to select all this data in advance and instead of the request, iterate over the data into arrays.

It is reluctant to write this mechanism by hand, most likely there should be ready-made solutions, in fact, the question is - does anyone know about something like that?

I heard that in .net there is a similar thing - DataTable is called.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
soines, 2011-03-01
@soines

Are you sure that such a selection in the code will work faster than a database query, given that there will be indexes correctly?

P
Puma Thailand, 2011-03-01
@opium

Give examples of queries and table structure.

R
Riateche, 2011-03-02
@Riateche

This does not require a ready-made solution. Just select the data you need, put it in memcached and keep it up to date (refresh the cache when the data changes or if there is no cache). It's just a few lines. Here's an example for you: www.php.net/manual/en/memcache.examples-overview.php
Better yet, just give the database more RAM for the cache, it's smart and will do everything for you.

E
eternals, 2011-03-02
@eternals

There are a lot of things in .net. In your case, there are 2 subcases: for these requests, it makes sense to make a view with a cache and select to it or not to take a steam bath and torment the database. In memory, it may be faster due to the lack of locks, but if the DBMS is normal, then everything will be fast for reading.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question