Skip to content

Instantly share code, notes, and snippets.

@vanchelo
Created April 23, 2014 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanchelo/11209448 to your computer and use it in GitHub Desktop.
Save vanchelo/11209448 to your computer and use it in GitHub Desktop.
<?php
use Illuminate\Cache\FileStore;
class ExtendedFileStore extends FileStore {
/**
* Get the expiration time based on the given minutes.
*
* @param int $seconds
* @return int
*/
protected function expiration($seconds) // Либо вот этот метод переписать, но только в FileStore
{
if ($seconds === 0) return 9999999999;
return time() + $seconds;
}
/**
* Store an item in the cache for a given number of minutes.
*
* @param string $key
* @param mixed $value
* @param int $minutes
* @return void
*/
public function put($key, $value, $minutes) // Либо вот так сделать, будет работать во всех xxxStore )
{
$minutes = $minutes / 60;
return parent::put($key, $value, $minutes);
}
}
@vanchelo
Copy link
Author

Если в своем сервис провайдере то вот так

$this->app['cache']->extend('extendedfile', function ($app) {
    $path = $app['config']['cache.path'];

    return new Repository(new ExtendedFileStore($app['files'], $path));
});

@vanchelo
Copy link
Author

Если не хочется заморачиваться с сервис провайдером, то в app/start/global.php

use Illuminate\Cache\Repository;

Cache::extend('extendedfile', function ($app) {
    $path = $app['config']['cache.path'];

    return new Repository(new ExtendedFileStore($app['files'], $path));
});

@vanchelo
Copy link
Author

И соответственно создать файл ExtendedFileStore.php, положить в удобное место и прописать его в composer.json в секцию autoload -> classmap, примерно так (файл лежит в папке app/extenders):

"app/extenders/ExtendedFileStore.php"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment