Download the PHP package davidecesarano/embryo-cache without Composer
On this page you can find all versions of the php package davidecesarano/embryo-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download davidecesarano/embryo-cache
More information about davidecesarano/embryo-cache
Files in davidecesarano/embryo-cache
Package embryo-cache
Short Description PSR-16 Simple Cache implementantion using PSR Stream.
License MIT
Homepage https://github.com/davidecesarano/embryo-cache
Informations about the package embryo-cache
Embryo Cache
A minimal PSR-16 cache implementation with file stream system.
Requirements
- PHP >= 7.1
- A PSR-7 http message implementation and PSR-17 http factory implementation (ex. Embryo-Http)
- A PSR response emitter (ex. Embryo-Emitter)
Installation
Using Composer:
Usage
Set Response and Emitter objects. Later, set the Cache object passing it the cache directory path.
In this example we check if the item cache test exists; if it not exists, we set test item cache with value Hello World! and the Time To Live (TTL) in 3600 seconds. Later, we get the test item cache with default value if item cache not exists.
Example
You may quickly test this using the built-in PHP server going to http://localhost:8000.
Options
setDefaultTtl($ttl)
You can set the default expiration TTL time. $ttl must be an integer or a DateInterval object.
Collection
Retrieving data
You may retrieve an item from the cache and you may also pass a default value as the second argument to the get method:
Storing data
The set method may be used to set a new value onto a cache with an optional expiration TTL time:
Deleting data
The delete method will remove a piece of data from the cache. If you would like the remove all data from the cache, you may use the clear method:
Retrieving multiple data
You may retrieve multiple items from the cache and you may also pass a default value as the second argument to the getMultiple method:
Storing multiple data
The setMultiple method may be used to set a multiple values onto a cache with an optional expiration TTL time:
Deleting multiple data
The deleteMultiple method will remove items from the cache:
Determining if an item exists in the cache
To determine if an item is present in the cache, you may use the has method. The has method returns true if the item is present and is not false:
All versions of embryo-cache with dependencies
psr/simple-cache Version 1.0.1
davidecesarano/embryo-http Version dev-master
davidecesarano/embryo-emitter Version dev-master