2017 © Pedro Peláez
 

library cache

Cache Modification helper for the Illuminate Cache package.

image

andrey-helldar/cache

Cache Modification helper for the Illuminate Cache package.

  • Thursday, May 17, 2018
  • by Helldar
  • Repository
  • 1 Watchers
  • 0 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 12 % Grown

The README.md

Laravel Cache

Laravel Cache, (*1)

Stable Version ![Unstable Version][badge_unstable] Total Downloads ![License][badge_license], (*2)

Installation

To get the latest version of Laravel Cache, simply require the project using Composer:, (*3)

$ composer require dragon-code/laravel-cache

Or manually update require block of composer.json and run composer update., (*4)

{
    "require": {
        "dragon-code/laravel-cache": "^2.0"
    }
}

Using

Keys And Tags

In addition to passing an explicit value, you can also pass objects and arrays to the keys and tags methods., (*5)

For example:, (*6)

use DragonCode\Cache\Services\Cache;
use DragonCode\SimpleDataTransferObject\DataTransferObject;

$arr1 = ['foo', 'bar']
$arr2 = new ArrayObject(['foo', 'bar'])
$arr3 = DataTransferObject::make(['foo', 'bar'])

Cache::make()->key($arr1)->tags($arr1);
Cache::make()->key($arr2)->tags($arr3);
Cache::make()->key($arr2)->tags($arr3);

Cache::make()->key([$arr1, $arr2, $arr3, 'foo', 'bar'])->tags([$arr1, $arr2, $arr3, 'foo', 'bar']);
Cache::make()->key([$arr1, $arr2, $arr3, 'foo', 'bar'])->tags([$arr1, $arr2, $arr3, 'foo', 'bar']);
Cache::make()->key([$arr1, $arr2, $arr3, 'foo', 'bar'])->tags([$arr1, $arr2, $arr3, 'foo', 'bar']);

Keys Handling

Since the main problem of working with the cache's key compilation, this package solves it., (*7)

By passing values to the keys method, we get a ready-made key at the output., (*8)

For example:, (*9)

use DragonCode\Cache\Services\Cache;

$cache = Cache::make()->key('foo', 'bar', [null, 'baz', 'baq']);

// Key is `acbd18db4cc2f85cedef654fccc4a4d8:37b51d194a7513e45b56f6524f2d51f2:73feffa4b7f6bb68e44cf984c85f6e88:b47951d522316fdd8811b23fc9c2f583`

This means that when writing to the cache, the tree view will be used., (*10)

For example:, (*11)

use DragonCode\Cache\Services\Cache;

Cache::make()->key('foo', 'foo')->put('foo');
Cache::make()->key('foo', 'bar')->put('bar');
Cache::make()->key('baz')->put('baz');

// acbd18db4cc2f85cedef654fccc4a4d8:
//     acbd18db4cc2f85cedef654fccc4a4d8: foo
//     37b51d194a7513e45b56f6524f2d51f2: bar
// 73feffa4b7f6bb68e44cf984c85f6e88: baz

When Enabled

Basic

By default, the cache will be written for 1 day., (*12)

use DragonCode\Cache\Services\Cache;

$cache = Cache::make()->key('foo', 'bar', ['baz', 'baq']);

$cache->put(static fn() => 'Some value');
// or
$cache->put('Some value');
// Contains cached `Some value`

$cache->get();
// Returns cached `Some value`

$cache->has();
// Returns `true`

$cache->forget();
// Will remove the key from the cache.

Custom TTL

The cache will be written for the specified number of minutes., (*13)

use DragonCode\Cache\Services\Cache;

$cache = Cache::make()
    ->ttl($minutes)
    ->key('foo', 'bar', ['baz', 'baq']);

$cache->put(static fn() => 'Some value');
// or
$cache->put('Some value');
// Contains cached `Some value`

$cache->get();
// Returns cached `Some value`

$cache->has();
// Returns `true`

$cache->forget();
// Will remove the key from the cache.

Tagged

For repositories that support tagging, the keys will be saved separated by tags., (*14)

use DragonCode\Cache\Services\Cache;

$cache = Cache::make()
    ->tags('actor', 'author')
    ->key('foo', 'bar', ['baz', 'baq']);

$cache->put(static fn() => 'Some value');
// or
$cache->put('Some value');
// Contains cached `Some value`

$cache->get();
// Returns cached `Some value`

$cache->has();
// Returns `true`

$cache->forget();
// Will remove the key from the cache.

To retrieve a tagged cache item, pass the same ordered list of tags to the tags method and then call the get method with the key you wish to retrieve:, (*15)

use DragonCode\Cache\Services\Cache;

$cache = Cache::make()->key('foo', 'bar');

$cache->tags('actor', 'author')->put(static fn() => 'Some value');
// or
$cache->tags('actor', 'author')->put('Some value');
// Contains cached `Some value`

$cache->tags('actor', 'author')->get();
// Returns cached `Some value`

$cache->tags('actor')->get();
// Returns `null`

$cache->tags('author')->get();
// Returns `null`

See the official Laravel documentation., (*16)

When Disabled

Passing when = false will not write to the cache., (*17)

use DragonCode\Cache\Services\Cache;

$cache = Cache::make()
    ->when(false)
    ->key('foo', 'bar');

$value = $cache->put(static fn() => 'Some value');
// or
$value = $cache->put('Some value');
// Returns `Some value`

$cache->get();
// Returns `null`

$cache->has();
// Returns `false`

License

This package's licensed under the MIT License., (*18)

The Versions

17/05 2018

dev-master

9999999-dev

Cache Modification helper for the Illuminate Cache package.

  Sources   Download

MIT

The Requires

 

laravel cache helper

05/02 2018

1.0.2

1.0.2.0

Cache Modification helper for the Illuminate Cache package.

  Sources   Download

MIT

The Requires

 

laravel cache helper

01/02 2018

1.0.1

1.0.1.0

Cache Modification helper for the Illuminate Cache package.

  Sources   Download

MIT

The Requires

 

laravel cache helper

01/02 2018

1.0.0

1.0.0.0

Cache Modification helper for the Illuminate Cache package.

  Sources   Download

MIT

The Requires

 

laravel cache helper

01/02 2018

dev-analysis-zDmjMn

dev-analysis-zDmjMn

Cache Modification helper for the Illuminate Cache package.

  Sources   Download

MIT

The Requires

 

laravel cache helper