PHP code example of neoacevedo / yii2-fastly-cache

1. Go to this page and download the library: Download neoacevedo/yii2-fastly-cache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

neoacevedo / yii2-fastly-cache example snippets


'components' => [
    'cache' => [
        'class' => 'neoacevedo\yii2\fastly\FastlyKvCache',
        'apiToken' => 'TU_FASTLY_API_TOKEN',
        'storeId' => 'TU_FASTLY_STORE_ID',
    ],
],

'components' => [
    'cache' => [
        'class' => 'neoacevedo\yii2\fastly\FastlyKvCache',
        'apiToken' => 'TU_FASTLY_API_TOKEN',
        'storeId' => 'TU_FASTLY_STORE_ID',
        'keyPrefix' => 'myapp_',
        'defaultDuration' => 3600, // 1 hora
    ],
],

// Guardar datos en caché
Yii::$app->cache->set('mi_clave', 'mi_valor', 3600);

// Obtener datos de caché
$valor = Yii::$app->cache->get('mi_clave');

// Verificar si existe una clave
if (Yii::$app->cache->exists('mi_clave')) {
    // La clave existe
}

// Eliminar una clave
Yii::$app->cache->delete('mi_clave');

use yii\caching\FileDependency;

$dependency = new FileDependency(['fileName' => 'path/to/file.txt']);
Yii::$app->cache->set('mi_clave', 'mi_valor', 3600, $dependency);

use yii\caching\TagDependency;

// Guardar con tags
Yii::$app->cache->set('usuario_1', $userData, 3600, new TagDependency(['tags' => 'usuarios']));

// Invalidar por tag
TagDependency::invalidate(Yii::$app->cache, 'usuarios');