📜 ⬆️ ⬇️

When files are no worse than memcached

Cache on files no slower memcached.
There is no need for memcached if you need a local (unallocated) cache with a size no more than free RAM.

We cache a simple array:
$array = array();
for ($i = 0; $i < 1000; $i++) {
$array []= sha1($i);
}
echo strlen(serialize($array)); // 53899

I made the cache on files like this:
file_put_contents($file, serialize(array($expire, $array)), LOCK_EX);
And checking $expire < time() on every receipt.

We count the time to get data from the cache (10,000 iterations).
file: 4.05 seconds
memcache: 4.07 seconds

Who still thinks that files are slow and their speed depends on the speed of the disk, read about Page cache .

')

Source: https://habr.com/ru/post/43412/


All Articles