PHP code example of trevorpe / laravel-symfony-cache

1. Go to this page and download the library: Download trevorpe/laravel-symfony-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/ */

    

trevorpe / laravel-symfony-cache example snippets


// config/cache.php

return [
    'stores' => [
        'file' => [
            'driver' => 'symfony',
            'adapter' => Symfony\Component\Cache\Adapter\ArrayAdapter::class,
        ],
    ]
]

// config/cache.php

return [
    'stores' => [
        'file' => [
            'driver' => 'symfony',
            'adapter' => Symfony\Component\Cache\Adapter\FilesystemAdapter::class,
            'path' => storage_path('framework/cache/data')
        ],
    ]
]

// config/cache.php

return [
    'stores' => [
        'file' => [
            'driver' => 'symfony',
            'adapter' => Symfony\Component\Cache\Adapter\FilesystemTagAwareAdapter::class,
            'path' => storage_path('framework/cache/data')
        ],
    ]
]

// config/cache.php

return [
    'stores' => [
        'redis' => [
            'driver' => 'symfony',
            'adapter' => Symfony\Component\Cache\Adapter\RedisAdapter::class,
            'connection' => env('REDIS_CACHE_CONNECTION', 'cache')
        ],
    ]
]

// config/cache.php

return [
    'stores' => [
        'redis' => [
            'driver' => 'symfony',
            'adapter' => Symfony\Component\Cache\Adapter\RedisTagAwareAdapter::class,
            'connection' => env('REDIS_CACHE_CONNECTION', 'cache')
        ],
    ]
]

Cache::set('test-key1', 'test-value1'); // Set the item without tags

Cache::get('test-key1'); // Gets the cache item normally
Cache::tags('tag1')->get('test-key1'); // Gets the cache item normally (unaffected by tags)

Cache::tags('tag1')->flush(); // Flushes nothing, as no values are tagged.
Cache::get('test-key1'); // Value is still present

Cache::flush(); // Flushes all cache entries normally
Cache::get('test-key1'); // Value has been removed

// --------------

Cache::tags('tag2')->set('test-key2', 'test-value2'); // Sets the item with a tag

Cache::get('test-key2'); // Gets the cache item normally
Cache::tags('tag2')->get('test-key2'); // Gets the cache item normally (unaffected by tags)

Cache::tags('tag2')->flush(); // Flushes only entries tagged with 'tag2'
Cache::flush(); // Flushes all cache entries normally

Cache::get('test-key2'); // Value will have been removed by either of the above flush() calls

// --------------

Cache::tags('tag3', 'tag4')->set('test-key3', 'test-value3'); // Sets the item with a tag

Cache::get('test-key3'); // Gets the cache item normally
Cache::tags('tag3')->get('test-key3'); // Unaffected. Gets the cache item normally

Cache::tags('tag3')->flush(); // Flushes only entries tagged with 'tag3'
Cache::tags('tag4')->flush(); // Flushes only entries tagged with 'tag4'
Cache::tags('tag3', 'tag4')->flush(); // Flushes only entries tagged with 'tag3' _or_ 'tag4'
Cache::flush(); // Flushes all cache entries normally

Cache::get('test-key3'); // Value will have been removed by any of the above flush() calls