Simple example of working with phpFastCache on files
Простой пример работы с phpFastCache на файлах

All English-language materials have been translated fully automatically using the Google service

When working on projects not on Bitrix, sometimes you need to ensure caching of certain data without resorting to working with MySQL. The phpfastcache library can help us with this

Putting the composer via ssh

  php -r "copy ('', 'composer-setup.php');"
php -r "if (hash_file ('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26 corruptd17af3ef010bf7cfb5cfb setup; setup; php ');} echo PHP_EOL; "
php composer-setup.php
php -r "unlink ('composer-setup.php');"  

Installing the phpfastcache

  composer require phpfastcache / phpfastcache  

You can familiarize yourself with the library itself here

Create a cache folder in any convenient place where our temporary files will be stored. We put the rights to it 755

The actual code

  require __DIR__. '/../../../vendor/autoload.php';

use Phpfastcache \ CacheManager;
use Phpfastcache \ Config \ Config;
use Phpfastcache \ Core \ phpFastCache;

// Setup File Path on your config files
CacheManager :: setDefaultConfig (new Config ([
    "path" => __DIR __. '/ cache',
    "itemDetailedDate" => false

function getVideoData ($ link) {

$ InstanceCache = CacheManager :: getInstance ('files');

$ CachedString = $ InstanceCache-> getItem (str_ireplace (array (':', '/', '?'), '', $ Link));

if (is_null ($ CachedString-> get ())) {
$ result = wp_remote_get ($ link. '/? utm_source = ig_web_copy_link & __ a = 1');
$ result = json_decode (wp_remote_retrieve_body ($ result));

$ url = $ result-> graphql-> shortcode_media-> video_url;
if ($ url) {
$ CachedString-> set ($ url) -> expiresAfter (11800 * 4 * 12); // in seconds, also accepts Datetime
$ InstanceCache-> save ($ CachedString); // Save the cache item just like you do with doctrine and entities

if (! empty ($ CachedString-> get ())) {
return $ CachedString-> get ();

$ videoSRC = getVideoData ($ item-> link);  


There are no comments yet, you can be the first to leave it

Leave a comment

The site uses a comment pre-moderation system, so your message will be published only after approval by the moderator

You are replying to a user's comment



Email me

Are you developing a new service, making improvements to the existing one and want to be better than your competitors? You have come to the right place. I offer you a comprehensive studio-level website development. From me you can order design, layout, programming, development of non-traditional functionality, implementation of communication between CMS, CRM and Data Analitics, as well as everything else related to sites, except for promotion.

Contact, I will always advise on all questions and help you find the most effective solution for your business. I am engaged in the creation of sites in Novosibirsk and in other regions of Russia, I also work with the CIS countries. You will be satisfied with our cooperation

An error occurred while sending, please try again after a while
Message sent successfully


+7(993) 007-18-96



Россия, г. Москва

By submitting the form, you automatically confirm that you have read and accept the Privacy Policy site

Contact with me
Send message
By submitting the form, you automatically confirm that you have read and accept Privacy policy of site
Sending successful!
Thank you for contacting :) I will contact you as soon as possible
Sending failed
An error occurred while sending the request. Please wait and try again after a while or call my phone number