Download the PHP package eribloo/laravel-cache-objects without Composer
On this page you can find all versions of the php package eribloo/laravel-cache-objects. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download eribloo/laravel-cache-objects
More information about eribloo/laravel-cache-objects
Files in eribloo/laravel-cache-objects
Package laravel-cache-objects
Short Description Strongly typed cache objects
License MIT
Homepage https://github.com/19932449-eribloo/laravel-cache-objects
Informations about the package laravel-cache-objects
Strongly typed cache objects
Introducing Laravel package that simplifies cache management by allowing you to encapsulate all details in one place. Improve your application cache maintanance with less raw strings and static typing.
You can later use this object to interract with cache:
Table of contents
- Installation
- Usage
- Creating
- CacheObject
- Key
- StringKey
- HashedKey
- Time-to-live
- Transformer
- JsonTransformer
- SerializeTransformer
- EncryptedTransformer
- GuardTransformer
- Traits
- CacheObjectActions
- Driver
- CacheDriver
- Events
- CacheObjectStored
- CacheObjectRetrieved
- CacheObjectMissed
- CacheObjectDeleted
- Extending
- PHPStan
- Testing
- Changelog
- Contributing
- Credits
- Licence
Installation
You can install the package via composer:
You can publish the config file with:
This is the contents of the published config file:
Usage
Creating
You can create basic Cache Object by running Artisan Command:
this will create class implementing EriBloo\CacheObjects\Contracts\CacheObject
in namespace specified in config with some defaults for you to configure.
CacheObject
EriBloo\CacheObjects\Contracts\CacheObject
interface requires you to implement 3 methods:
Key
Key interface is a wrapper for Stringable interface responsible for preparing key for storage. Currently 2 options exist.
StringKey
Basic key that accepts string.
HashedKey
Decorator for other keys that returns hashes key before storage. Accepts optional algorithm in constructor (sha256
by default).
Time-to-live
Defined with Carbon\CarbonInterval
. Values that resolve to 0 or less seconds are considered to be stored forever.
Transformer
Transformers are classes responsible for modifying values before storage and after retrieval.
JsonTransformer
Uses json_encode
on save and json_decode
on load. Accepts optional flags and depth in constructor.
SerializeTransformer
Transformer that uses PHP serialize
on save and unserialize
on load. Accepts optional class-string[]|bool
in constructor to specify classes allowed for deserialization.
EncryptedTransformer
Decorator for other transformer that uses Crypt::encryptString
on save and Crypt::decryptString
on load.
GuardTransformer
Proxy for other transformer that doesn't modify values, but instead validates them before storage or after retrieval. This class accepts up to 2 closures that should throw an Exception when provided value is invalid.
Traits
CacheObjectActions
Optional (but helpful) trait that adds usage methods:
Driver
This interface defines methods used for interacting with storage. Currently 1 class exists.
CacheDriver
This class is a default driver that accepts an instance of Illuminate\Contracts\Cache\Store
. Binding defined in Service Provider resolves this to your default cache storage.
Events
Default driver dispatches events:
CacheObjectStored
When object is put in storage.
CacheObjectRetrieved
When object is retrieved from storage.
CacheObjectMissed
When cache object retrieval misses.
CacheObjectDeleted
When cache object is removed from storage.
Extending
I created this package with ease of configuration in mind so you can easly create Key
, Transformer
or Driver
that will suit your needs. Additionally if you have any ideas of classes that could be incorporated into main package feel free to open an Issue or Pull Request.
PHPStan
While I omited most of static typing in examples above for clarity, this package is developed with level 8 of PHPStan and parts of code that are working with mixed
values (transformers, cache object interface and cache object action) are built with generics.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
All contributions are welcome.
Credits
- EriBloo
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-cache-objects with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^10.0||^11.0