Download the PHP package omnilog/psr6-dynamo-db without Composer
On this page you can find all versions of the php package omnilog/psr6-dynamo-db. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download omnilog/psr6-dynamo-db
More information about omnilog/psr6-dynamo-db
Files in omnilog/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
Fork of https://github.com/OmnilogSage/DynamoDbCachePsr6 to use AWS Async DynamoDb.
Library for storing cache in DynamoDB implementing the PSR-6 and PSR-16 interfaces. See also Symfony bundle of this library.
Installation
composer require omnilog/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 \Omnilog\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
\Omnilog\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
\Omnilog\DynamoDbCache\Encoder\CacheItemEncoderInterface
interface:
All versions of psr6-dynamo-db with dependencies
php Version ^7.3 | ^8.0
async-aws/dynamo-db Version ^1.0
psr/simple-cache Version ^1.0