Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3918

How to store an array to the cache in Symfony?

$
0
0

I have an array to display from database and after many business implementations which is taking time of 1~2 minute to get me final output. So this process is annoying me while testing with UI. So I decide to store this final array into the cache. I have tried following lines of code to store myArray into cache.

use Symfony\Component\Cache\Adapter\FilesystemAdapter;use Symfony\Contracts\Cache\ItemInterface;$cache = new FilesystemAdapter();// The callable will only be executed on a cache miss.$output = $cache->get('my_cache_key', function (ItemInterface $item) use ($myArray) {    $item->expiresAfter(7200);    return $this->serializer->provideSerializer()->serialize($myArray, 'json');});

I think when read from cache should be faster but it is still taking the same time to load data.

Can anybody please help me how can I store my array to the cache so next time it will be faster to load.

Thank You.


Viewing all articles
Browse latest Browse all 3918

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>