Download the PHP package rikudou/psr6-dynamo-db without Composer
On this page you can find all versions of the php package rikudou/psr6-dynamo-db. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rikudou/psr6-dynamo-db
More information about rikudou/psr6-dynamo-db
Files in rikudou/psr6-dynamo-db
Package psr6-dynamo-db
Short Description PSR-6 and PSR-16 cache implementation using AWS DynamoDB
License MIT
Informations about the package psr6-dynamo-db
Library for storing cache in DynamoDB implementing the PSR-6 and PSR-16 interfaces. See also Symfony bundle of this library.
Since version 2 this library uses the lightweight async-aws/dynamo-db instead of the full AWS SDK.
Installation
composer require rikudou/psr6-dynamo-db
Usage
The usage is pretty straight-forward, you just define the details in constructor and then use it as any other PSR-6 or PSR-16 implementation:
It's recommended to use the builder for creating new instances. The builder is immutable and every method returns a new instance.
The default values for fields are:
- primary key -
id
(string) - ttl field -
ttl
(number) - value field -
value
(string)
You must create the DynamoDB table before using this library.
Basic example:
Example using the PSR-16 interface:
Prefixing
You can automatically prefix all keys in DynamoDB by using the prefix configuration like this:
Converters
This implementation supports all instances of \Psr\Cache\CacheItemInterface
with the use of converters which
convert the object to \Rikudou\DynamoDbCache\DynamoCacheItem
. Note that some information may be lost in the
conversion, notably expiration date.
You can write your own converter for your specific class which includes support for expiration date like this:
You then need to register it in the converter and assign the converter to the cache:
Encoders
By default the values are serialized using php serializer. If you want to share the cache with apps
in other languages (or different php app that doesn't have the same classes), you can either use the
\Rikudou\DynamoDbCache\Encoder\JsonItemEncoder
or write your own.
Note: The JsonItemEncoder is lossy when it comes to objects, if you need to store object information this encoder might not be for you. If you on the other hand only store scalar data and/or arrays the JsonItemEncoder is enough.
Example using JsonItemEncoder
Your values will now be saved json encoded in DynamoDB.
Writing your own encoder is easy, you just need to implement the
\Rikudou\DynamoDbCache\Encoder\CacheItemEncoderInterface
interface:
All versions of psr6-dynamo-db with dependencies
php Version ^8.0
rikudou/clock Version ^1.0
psr/simple-cache Version ^1.0
async-aws/dynamo-db Version ^1.0