PHPackages                             omnilog/psr6-dynamo-db-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. omnilog/psr6-dynamo-db-bundle

ActiveSymfony-bundle[Caching](/categories/caching)

omnilog/psr6-dynamo-db-bundle
=============================

PSR-6 and PSR-16 cache implementation using AWS DynamoDB for Symfony

0.0.1(4y ago)010MITPHPPHP ^7.2 | ^8.0

Since May 26Pushed 4y agoCompare

[ Source](https://github.com/omnilog/DynamoDbCachePsr6Bundle)[ Packagist](https://packagist.org/packages/omnilog/psr6-dynamo-db-bundle)[ RSS](/packages/omnilog-psr6-dynamo-db-bundle/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (6)Versions (2)Used By (0)

[![Tests](https://github.com/OmnilogSage/DynamoDbCachePsr6Bundle/workflows/Tests/badge.svg)](https://github.com/OmnilogSage/DynamoDbCachePsr6Bundle/actions?query=workflow%3ATests)[![Coverage Status](https://camo.githubusercontent.com/a03b894ea0b7e94dd4d3e8199566ee35ab40516e0d2f2b899e68650c47a4d1f0/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4f6d6e696c6f67536167652f44796e616d6f446243616368655073723642756e646c652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/OmnilogSage/DynamoDbCachePsr6Bundle?branch=master)

Don't use Symfony? Use the [standalone library](https://github.com/OmnilogSage/DynamoDbCachePsr6).

Installation
------------

[](#installation)

`composer require omnilog/psr6-dynamo-db-bundle`

Configuration
-------------

[](#configuration)

Create the file `config/packages/dynamo_db_cache.yaml` and put at least the table name there:

```
omnilog_dynamo_db_cache:
    table: myCacheTableName
```

Everything else has default values, though you probably want to also configure the dynamo db client.

### Configuration options:

[](#configuration-options)

- `replace_default_adapter` - set to `true` to replace the default `AdapterInterface` and `CacheInterface`implementation with the adapter from this bundle (default: **false**)
- `table` - the table which will be used for storing the cache (**required**)
- `client_service` - The service that will be used as DynamoDB client, if not set this bundle will try to create one (more details in `client_config` option below) but the use is limited
- `client_config` - If no `client_service` is configured, it will be created from the values of this config. It contains two subkeys:
    - `region` - the AWS region (default: **us-east-1**)
    - `version` - the service version (default: **latest**)
    - no other options are available, if you need to configure more, please create and assign custom `client_service`
- `encoder` - contains the settings for encoders:
    - `service` - the service which will be used as the encoder
        - can be one of built-in services (`omnilog.dynamo_cache.encoder.serialize`, `omnilog.dynamo_cache.encoder.json`)
        - can be a custom service implementing the `\Omnilog\DynamoDbCache\Encoder\CacheItemEncoderInterface` interface
        - default value: **omnilog.dynamo\_cache.encoder.serialize**
    - `json_options` - settings for the json encoder, ignored if another encoder is used
        - `encode_flags` - the same flags you would pass to `json_encode()`
        - `decode_flags` - the same flags you would pass to `json_decode()`
        - `depth` - the depth argument for both `json_encode()` and `json_decode()`
- `primary_key_field` - the name of the field that will be used as the primary key (default: **id**)
- `ttl_field` - the name of the field that will be used as the ttl field (default: **ttl**)
- `value_field` - the name of the field that will be used as the value field (default: **value**)
- `key_prefix` - the prefix used in front of the item keys (default: **null** which means none)

Autogenerated default config (via `bin/console config:dump omnilog_dynamo_db_cache`):

```
# Default configuration for extension with alias: "omnilog_dynamo_db_cache"
omnilog_dynamo_db_cache:

    # Replace default cache adapter with this one
    replace_default_adapter: false

    # The DynamoDB table to use as cache
    table:                null

    # The service to use as the Dynamo DB client
    client_service:       null

    # The Dynamo DB client configuration. If you need finer tuning, create the service yourself and assign it in client_service
    client_config:

        # The AWS region
        region:               us-east-1

        # The service version
        version:              latest
    encoder:

        # The service to be used as the encoder/decoder
        service:              omnilog.dynamo_cache.encoder.serialize

        # Settings for the json encoder
        json_options:

            # The flags that will be passed when encoding
            encode_flags:         0

            # The flags that will be passed when decoding
            decode_flags:         0

            # The depth of the JSON parsing for encoding/decoding
            depth:                512

    # Session related configuration
    session:

        # The ttl for the session, defaults to ini setting session.gc_maxlifetime
        ttl:                  null

        # The prefix for sessions
        prefix:               session_

    # The field to be used as primary key
    primary_key_field:    id

    # The field to be used as ttl
    ttl_field:            ttl

    # The field to be used as value
    value_field:          value

    # The prefix used in front of keys when storing
    key_prefix:           null
```

Usage
-----

[](#usage)

You can use one of the two available services:

- `Omnilog\DynamoDbCache\DynamoDbCache` - this one doesn't implement the Symfony `AdapterInterface` nor `CacheInterface`
- `Omnilog\DynamoDbCacheBundle\Cache\DynamoDbCacheAdapter` - this one implements the Symfony `AdapterInterface` and `CacheInterface`

If you set the `replace_default_adapter` to `true` you can also use these interfaces as services:

- `Symfony\Component\Cache\Adapter\AdapterInterface` - the Symfony interface for PSR-6 cache
- `Symfony\Contracts\Cache\CacheInterface` - the Symfony interface for simple cache
- `Psr\Cache\CacheItemPoolInterface` - the PSR-6 interface
- `Psr\SimpleCache\CacheInterface` - the PSR-16 interface

### Example

[](#example)

```
