We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Caching PHP array

Hello, I'm trying to figure out the best way to cache a php array, I have a library called "Assets" and this library contains a custom "compiler" that returns something like this:

array('modules' => [ 'core' => '/app/assets/js/core.js', '$' => '/app/assets/js/$.js', 'bootloader' => '/app/assets/js/bootloader.js', ], 'dependencies' => [ 'core' => ['$', 'bootloader'], ], );

and I wan't to cache this array to avoid the "searching" process on every request. Should i use which caching method ? (memcache, libmemcached or other?) Should I create a service for the assets caching method ?


or a cache for every lib? (memcached for example):


I would just use only one memcached service with proper adapter and cache just array with key assetsCache


The backend appears to not do anything to data. It is the frontend that serializes data or does nothing. The Data frontend serializes the data to a string. The None frontend does not serialize the data, letting you store serialized arrays along side images. Choose the frontend first.

The backend can be whatever is fastest or already installed on your system. The backend appears to treat everything as strings created by the frontend. It looks like all backends work with any frontend.

Creating a service has one main advantage, you can access it anywhere the $di exists, which is almost everywhere.