PHP code example of natsumework / laravel-cache-manager

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

    

natsumework / laravel-cache-manager example snippets


php artisan vendor:publish --provider="Natsumework\CacheManager\CacheManagerServiceProvider"

return [
    // ...

    /*
    |--------------------------------------------------------------------------
    | Cache Types
    |--------------------------------------------------------------------------
    | Before you put item into the cache storage, you have to define the type first.
    |
    | You can also define `ttl`, `hotspot_protection`, `penetrate_protection`,
    | `hotspot_protection_ttl` for each type. It takes precedence over a globally defined one.
    |
    */
    'types' => [
        'user' => [
            'ttl' => 300, // seconds
            'hotspot_protection' => true,
            'penetrate_protection' => true,
            'hotspot_protection_ttl' => 10, // seconds
        ],
        'active_users' => [
            'ttl' => 60 * 60,
            'hotspot_protection' => false,
            'penetrate_protection' => false,
        ],
        'post' => [],

        // ...
    ],

    // ...
];

use Natsumework\CacheManager\Facades\CacheManager;

// CacheManager::remember($type, $index = null, \Closure $callback = null)

// you must define type `user` in config/cache-manager.php
$user = CacheManager::remember('user', 1, function () {
    return User::find(1);
});

$data = CacheManager::remember('type', 999, function () {
    return null;
});

// If `penetration_protection` is enabled, $data === false
// If `penetration_protection` is not enabled, $data === null

use Natsumework\CacheManager\Facades\CacheManager;

// CacheManager::get($type, $index = null, $default = null)

// you must define type `user` in config/cache-manager.php
$user = CacheManager::get('user', 1, 'user not found');

use Natsumework\CacheManager\Facades\CacheManager;

// CacheManager::put($type, $index = null, $value = null)

// you must define type `user` in config/cache-manager.php
CacheManager::put('user', 1, User::find(1));