Download the PHP package andrey-helldar/cache without Composer
On this page you can find all versions of the php package andrey-helldar/cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download andrey-helldar/cache
More information about andrey-helldar/cache
Files in andrey-helldar/cache
Package cache
Short Description An improved interface for working with cache
License MIT
Informations about the package cache
Smart Cache for Laravel
Installation
To get the latest version of Smart Cache
, simply require the project using Composer:
Or manually update require
block of composer.json
and run composer update
.
Using
Keys And Tags
In addition to passing an explicit value, you can also pass objects and arrays to the keys
and tags
methods.
For example:
Unpacking and processing of objects occurs as follows:
Keys Handling
Since the main problem of working with the cache's key compilation, this package solves it.
By passing values to the keys
method, we get a ready-made key at the output.
The hash is formed by the value key=value
, which allows avoiding collisions when passing identical objects.
In the case of passing nested arrays, the key is formed according to the principle key1.key2=value
, where key1
and key2
are the keys of each nested array.
For example:
This means that when writing to the cache, the tree view will be used.
For example:
Disable key hashing
In some cases, you need to disable the use of the key hashing mechanism.
To do this, simply call the hashKey(false)
method:
With Authentication
In some cases, it is necessary to bind the cache to certain users. To do this, we have added the withAuth
helper.
When processing requests with a call to the withAuth method, the binding will be carried out not only by identifier, but also by reference to the model class, since a project can have several models with the possibility of authorization.
For example, App\Models\Employee
, App\Models\User
.
When Enabled
Basic
Method Call Chain
Sometimes in the process of working with a cache, it becomes necessary to call some code between certain actions, and in
this case the call
method will come to the rescue:
In addition, the forget
method now returns an instance of the Cache
object, so it can be used like this:
Previously, you had to use the following sequence:
Custom TTL
By default, the cache will be written for 1 day.
The cache will be written for the specified number of minutes, seconds or the DateTimeInterface
instance.
It does not matter in which direction the time shift will be. During processing, the value is converted to the abs()
.
As Minutes
As Seconds
By Objects And Custom Strings
You can also store all TTL values in one place - in the config/cache.php
file.
To do this, add a ttl
block to the file and define
a TTL for the objects.
After that you can use the following construction:
If the value is not found, the default value will be taken, which you can also override in the configuration file.
With Contract
Starting with version 2.9.0
, we added the
ability to dynamically specify TTLs in objects. To do this, you
need to implement the DragonCode\Contracts\Cache\Ttl
contract into your object and add a method that returns one of
the following types of variables: DateTimeInterface
, Carbon\Carbon
, string
or integer
.
This method will allow you to dynamically specify the TTL depending on the code being executed.
For example:
Tagged
For repositories that support tagging, the keys will be saved separated by tags.
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:
See the official Laravel documentation.
When Disabled
Passing when = false
will not write to the cache.
You can also define whether to enable or disable the use of cache storage in the settings.
For example:
License
This package's licensed under the MIT License.
All versions of cache with dependencies
dragon-code/contracts Version ^2.16
dragon-code/support Version ^5.6
illuminate/support Version ^6.0 || ^7.0 || ^8.0 || ^9.0