2017 © Pedro Peláez
 

library cache-key

Library that allows you to generate cache keys based on various data formats.

image

ecomdev/cache-key

Library that allows you to generate cache keys based on various data formats.

  • Friday, May 20, 2016
  • by IvanChepurnyi
  • Repository
  • 1 Watchers
  • 7 Stars
  • 736 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 80 % Grown

The README.md

Cache Key Build Status Coverage Status

Library that allows you to generate cache keys based on various data formats., (*1)

Main components: * Key generator Allows to generate a cache key based on different data input * Key converters Allows to convert various php data types into key friendly data type * Key normalizer Normalizes characters in generated string to match particular cache key sanity checks of your own cache adapter., (*2)

Installation

composer require ecomdev/cache-key

Usage

Automatic non alpha-num characters encoding

use EcomDev\CacheKey\Normalizer\EncodeNormalizer;
use EcomDev\CacheKey\Generator;

$generator = new Generator(new EncodeNormalizer());
$generator->generate('some_bad_#^.;:/\\_character'); // Generates "some_bad_235e2e3b3a2f5c_character"

Multiple normalizers

use EcomDev\CacheKey\Normalizer\EncodeNormalizer;
use EcomDev\CacheKey\Normalizer\LengthNormalizer;
use EcomDev\CacheKey\NormalizerChain;
use EcomDev\CacheKey\Generator;

$normalizer = new NormalizerChain([
    new EncodeNormalizer(),
    new LengthNormalizer(16)
]);

$generator = new Generator($normalizer);
$generator->generate('some_bad_#^.;:/\\_character'); // Generates "some_bad_235e2e3b3a2f5c_character"

Using converter for key value map

use EcomDev\CacheKey\Normalizer\EncodeNormalizer;
use EcomDev\CacheKey\Converter\KeyValueConverter;
use EcomDev\CacheKey\Converter\ScalarConverter;
use EcomDev\CacheKey\Generator;

$generator = new Generator(
    new EncodeNormalizer(), 
    new KeyValueConverter(new ScalarConverter())
);

$generator->generate([
    'some-key' => 'some-value', 
    'another-key' => 'another-value'
]); // Generates "some-key_some-value_another-key_another-value"

Cache Key Info Provider Usage

Your custom cache able model, (*3)

class YourCustomModel implements EcomDev\CacheKey\InfoProviderInterface
{
    public function getCacheKeyInfo()
    {
        return [
            'some-key' => 'some-value', 
            'another-key' => 'another-value'
        ];
    }
}

Usage in key generation, (*4)

use EcomDev\CacheKey\Normalizer\EncodeNormalizer;
use EcomDev\CacheKey\Converter\KeyValueConverter;
use EcomDev\CacheKey\Converter\ScalarConverter;
use EcomDev\CacheKey\Generator;

$object = new YourCustomModel();

$generator = new Generator(
    new EncodeNormalizer(), 
    new KeyValueConverter(new ScalarConverter())
);

$generator->generate($object); // Generates "some-key_some-value_another-key_another-value"

PSR-6 compatible key generation

use EcomDev\CacheKey\Normalizer\Psr6Normalizer;
use EcomDev\CacheKey\Generator;

$generator = new Generator(Psr6Normalizer::create());
$generator->generate('give_me-psr-6-compatible_#^.;:/\\-key'); // Generates "give_me-psr-6-compatible_235e.3b3a2f5c-key"

Prefixed Key Generation

use EcomDev\CacheKey\Normalizer\Psr6Normalizer;
use EcomDev\CacheKey\Generator;

$generator = new Generator(Psr6Normalizer::create(), null, 'prefix-');
$generator->generate('some-non-prefixed-key'); // Generates "prefix-some-non-prefixed-key"

Contribution

Make a pull request based on develop branch, (*5)

The Versions

20/05 2016

dev-develop

dev-develop

Library that allows you to generate cache keys based on various data formats.

  Sources   Download

MIT

The Requires

  • php ^5.6|>=7.0

 

The Development Requires

20/05 2016

dev-master

9999999-dev

Library that allows you to generate cache keys based on various data formats.

  Sources   Download

MIT

The Requires

  • php ^5.6|>=7.0

 

The Development Requires

20/05 2016

1.1.0

1.1.0.0

Library that allows you to generate cache keys based on various data formats.

  Sources   Download

MIT

The Requires

  • php ^5.6|>=7.0

 

The Development Requires

05/05 2016

1.0.0

1.0.0.0

Library that allows you to generate cache keys based on various data formats.

  Sources   Download

MIT

The Requires

  • php ^5.6|>=7.0

 

The Development Requires