Giter Club home page Giter Club logo

le7-cache-memcache's Introduction

Memcache and memcached apapters for rnr1721/le7-cache

It make enable to use memcache or memcached with le7-framework or any PHP project

Requirements

  • PHP 8.1 or higher.
  • Composer 2.0 or higher.

What it can?

  • Standard implementation of PSR-16 Simple Cache
  • Out of the box can use Filesystem, memory and session adapters
  • Use memcache and memcached for caching

Installation

composer require rnr1721/le7-cache-memcache

Testing

composer test

How it works?

use Core\Cache\SCFactoryMemcacheGeneric;

$cacheFactory = new SCFactoryMemcacheGeneric();

// For memcache
$cache = $cacheFactory->getMemcache("127.0.0.1", 11211);
// For memcached
$cache = $cacheFactory->getMemcached("127.0.0.1", 11211);

$data = [
    'value1' => 'The 1 value',
    'value2' => 'The 2 value'
    ];

// Put data in cache
// Set cache key, value and time-to-live
$cache->set('mykey', $data, 5000);

// Get value from cache
$result = $cache->get('mykey');

print_r($result);

implemented methods

use Psr\SimpleCache\CacheInterface;

    public function get(string $key, mixed $default = null): mixed;

    public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool;

    public function delete(string $key): bool;

    public function clear(): bool;

    public function getMultiple(iterable $keys, mixed $default = null): iterable;

    public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool;

    public function deleteMultiple(iterable $keys): bool;

    public function has(string $key): bool;

factory methods

use Core\Cache\Interfaces\SCFactoryMemcache;

    /**
     * Get memcache instance of SimpleCache
     * @param string $host Memcache host
     * @param int $port Memcache port
     * @return CacheInterface
     */
    public function getMemcache(string $host = "127.0.0.1", int $port = 11211): CacheInterface;

    /**
     * Get memcached instance of SimpleCache
     * @param string $host Memcached host
     * @param int $port Memcached port
     * @return CacheInterface
     */
    public function getMemcached(string $host = "127.0.0.1", int $port = 11211): CacheInterface;

le7-cache-memcache's People

Contributors

rnr1721 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.