revenuewire / simple-cache
RW Simple Cache
Installs: 2 235
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- aws/aws-sdk-php: ^3.53
- psr/simple-cache: ^1.0
Requires (Dev)
- php-coveralls/php-coveralls: ^1.0
- phpunit/phpunit: ^6.2
This package is auto-updated.
Last update: 2024-12-12 06:32:25 UTC
README
Install
composer require revenuewire/simple-cache
About
A PSR-16 "Simple Cache" implementation for adding cache to your applications.
Adapters
The following cache adapters are available:
- Array
- APCu
- DyanamoDB
- File
Examples
<?php /** * File Cache */ $cache = new \RW\FileCache("/tmp/unit-test-" . uniqid()); $k = "hello"; $v = "world"; $cache->set($k, $v); //return true $cache->get($k); //world $cache->has($k); //true $cache->delete($k); //true $cache->get($k); //null $cache->has($k); //false /** * DynamoDB Cache */ $region = "us-west-1"; $tableName = "sandbox-demo-cache"; $cache = new \RW\DynamoCache($tableName, [ "region" => $region, ]);
Run unittest
sh ./bin/go-test.sh
DynamoDB Schema
AWSTemplateFormatVersion: '2010-09-09' Description: (2-resources) DynamoDB Cache v1.0.0 Parameters: EnvironmentType: Description: The environment type Type: String Default: sandbox AllowedValues: - production - sandbox ConstraintDescription: must be a production or sandbox APP: Description: APP Name Type: String AllowedPattern: "^[a-z0-9-]+$" Default: "demo" MinLength: 4 MaxLength: 30 Mappings: BuildEnvironment: sandbox: "env": "sandbox" "capacityUnits": 5 production: "env": "production" "capacityUnits": 5 Resources: DynamoDBTable: Type: AWS::DynamoDB::Table Properties: TableName: !Sub "${EnvironmentType}-${APP}-cache" AttributeDefinitions: - AttributeName: id AttributeType: S KeySchema: - AttributeName: id KeyType: HASH ProvisionedThroughput: ReadCapacityUnits: { "Fn::FindInMap" : [ "BuildEnvironment", { "Ref" : "EnvironmentType" }, "capacityUnits"]} WriteCapacityUnits: { "Fn::FindInMap" : [ "BuildEnvironment", { "Ref" : "EnvironmentType" }, "capacityUnits"]} TimeToLiveSpecification: AttributeName: expiry Enabled: true