CodeIgniter Forums
Logical help for storing data in cache or no - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Logical help for storing data in cache or no (/thread-52449.html)



Logical help for storing data in cache or no - El Forum - 06-11-2012

[eluser]veledrom[/eluser]
Hi,

This is pagination purposes.

I have a table with 2.000.000+/- records in database. My query returns average 20.000 records. I store it in cache philsturgeon for 5 minutes so every page request done in 5 minutes reads records from cache, no query sent to database.

I know that we normally send queries to database with LIMIT and OFFSET parts (takes about 2 minutes) but in this case same logic is applied against cache with array_slice(array, OFFSET, LENGTH) function (takes less than half a second).

Do you think sending queries to database is better than using cache in this case, or I'm on right track?


Code:
$cache_name = $this->cache_name_initials . '-' . $postcode . '-' . $within;
  
if (! $this->cache->get($cache_name))
{
$query_result = $this->geomaps_model->get_near_places($postcode, $within);
$cache_content['Created'] = date('H:i:s');
$cache_content['Content'] = $query_result->result();
$this->cache->write($cache_content, $cache_name, $this->cache_timeout);
}

$search_result = $this->cache->get($cache_name);

Thanks