ministryofjustice / aws-secrets-cache-php
AWS Secrets Manager caching for PHP (PSR-16, APCu cache storage, ENV-prefixed secrets).
Package info
github.com/ministryofjustice/aws-secrets-cache-php
pkg:composer/ministryofjustice/aws-secrets-cache-php
Requires
- php: ^8.2
- aws/aws-sdk-php: ^3.198
- psr/simple-cache: ^1.0 || ^2.0 || ^3.0
Requires (Dev)
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.10
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main
- v2.2.0
- v2.1.8
- v2.1.7
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.1.1
- v1.1.0
- v1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-renovate-all-minor-patch-updates
- dev-renovate-github-minor-patch-updates
- dev-renovate-squizlabs-php-codesniffer-4-x
- dev-renovate-phpunit-phpunit-13-x
This package is not auto-updated.
Last update: 2026-10-13 09:53:02 UTC
README
Reusable helper class to fetch secrets at runtime from AWS Secrets Manager with a cache to reduce duplicate requests.
Requires a pre-configured cache implementing StorageInterface from laminas-cache.
Installation
composer require ministryofjustice/aws-secrets-cache-php
Usage
use Aws\SecretsManager\SecretsManagerClient; use Laminas\Cache\Storage\StorageInterface; use MoJ\AwsSecretsCache\AwsSecretsCache; $storage = /** instanceof StorageInterface */; $smClient = new SecretsManagerClient([...]); $secretsCache = new AwsSecretsCache(null, $storage, $smClient); $mySecret = $secretsCache->getValue('my-secret');
The first parameter optionally defines a namespace that will apply to all secrets retrieved by that instance of the class. The following example would return the secret named namespace/my-secret:
$secretsCache = new AwsSecretsCache('namespace', ...); $myNamespacedSecret = $secretsCache->getValue('my-secret');
You can use clearCache to remove an item from the underlying cache:
$mySecret = $secretsCache->getValue('my-secret'); $secretsCache->clearCache('my-secret'); $mySecret = $secretsCache->getValue('my-secret'); // Will fetch from AWS again
TTL must be implemented on the storage class, it is not applied by AwsSecretsCache.