Simple cache abstraction layer implementing PSR-16

Related tags

Caching cache
Overview

sabre/cache

This repository is a simple abstraction layer for key-value caches. It implements PSR-16.

If you need a super-simple way to support PSR-16, sabre/cache helps you get started. It's as hands-off as possible.

It also comes with a test-suite that can be used by other PSR-16 implementations.

Installation

Make sure you have composer installed, and then run:

composer require sabre/cache

Usage

Read PSR-16 for the API. We follow it to the letter.

In-memory cache

This is useful as a test-double or long running processes. The Memory cache only lasts as long as the object does.

$cache = new \Sabre\Cache\Memory();

APCu cache

This object uses the APCu api for caching. It's a fast memory cache that's shared by multiple PHP processes.

$cache = new \Sabre\Cache\Apcu();

Memcached cache

This object uses the Memcached extension for caching.

$memcached = new \Memcached();
$memcached->addServer('127.0.0.1', 11211);
$cache = new \Sabre\Cache\Memcached($memcached);

You are responsible for configuring memcached, and you just pass a fully instantiated objected to the \Sabre\Cache\Memcached constructor.

Build status

branch status
master Build Status

Questions?

Head over to the sabre/dav mailinglist, or you can also just open a ticket on GitHub.

Made at fruux

This library is being developed by fruux. Drop us a line for commercial services or enterprise support.

Comments
  • Change CI from Travis to GitHub Actions

    Change CI from Travis to GitHub Actions

    Add a first GitHub workflow CI. I expect that the PHP "extensions" list will need to be expanded. But I think that I have to merge first, in order to get the first run. So there is likely to be a followup PR.

    opened by phil-davis 5
  • Update infrastructure 20200126

    Update infrastructure 20200126

    1. require PHP 7.1 or later and phpunit 7
    2. test on PHP 7.1 through 7.4
    3. switch to "standard" php-cs-fixer for code style
    4. add phpstan.neon and run on CI at level 1 (which passes)
    opened by phil-davis 5
  • Standardize CI 20200203

    Standardize CI 20200203

    • cleanup .gitignore
    • implement Travis like in skel (separate phpstan job, --prefer-lowest in matrix)
    • apply php-cs-fixer changes for tests folder
    • move tests into tests/Cache and adjust composer autoload-dev section to fix phpstan:
    composer phpstan
    > @php vendor/bin/phpstan analyse lib tests
    Note: Using configuration file /home/phil/git/sabre-io/cache/phpstan.neon.
     10/10 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
    
     ------ ------------------------------------------------------------------- 
      Line   tests/Cache/AbstractCacheTest.php                                  
     ------ ------------------------------------------------------------------- 
             Class Sabre\Cache\AbstractCacheTest was not found while trying to  
             analyse it - autoloading is probably not configured properly.      
     ------ ------------------------------------------------------------------- 
    
     ------ ----------------------------------------------------------------------- 
      Line   tests/Cache/ApcuTest.php                                               
     ------ ----------------------------------------------------------------------- 
             Class Sabre\Cache\ApcuTest was not found while trying to analyse it -  
             autoloading is probably not configured properly.                       
     ------ ----------------------------------------------------------------------- 
    
     ------ ----------------------------------------------------------------------- 
      Line   tests/Cache/MemcachedTest.php                                          
     ------ ----------------------------------------------------------------------- 
             Class Sabre\Cache\MemcachedTest was not found while trying to analyse  
             it - autoloading is probably not configured properly.                  
     ------ ----------------------------------------------------------------------- 
    
     ------ ----------------------------------------------------------------- 
      Line   tests/Cache/MemoryCacheTest.php                                  
     ------ ----------------------------------------------------------------- 
             Class Sabre\Cache\MemoryCacheTest was not found while trying to  
             analyse it - autoloading is probably not configured properly.    
     ------ ----------------------------------------------------------------- 
    
     [ERROR] Found 4 errors                                                         
    
    Script @php vendor/bin/phpstan analyse lib tests handling the phpstan event returned with error code 1
    

    (I made it the similar pattern to what happens in vobject )

    opened by phil-davis 4
  • Correct some minor typos and get unit tests running correctly

    Correct some minor typos and get unit tests running correctly

    This PR is really an excuse to make the new GitHub workflows run, and get them passing.

    1. correct some minor typos
    2. add a return to the end of deleteMultiple which was missing (report by code analysis)
    3. Setup memcached server and apcu for tests

    This makes all 72 unit tests run and pass, like they did with Travis.

    opened by phil-davis 3
  • Use latest php-cs-fixer 2.17.1

    Use latest php-cs-fixer 2.17.1

    The latest php-cs-fixer finds some new things. Code changes were needed in https://github.com/sabre-io/dav/pull/1316 for sabre/dav. We might as well consistently make sure to use at least this version 2.17.1 in all repos so that we are doing consistent code-style checking.

    It complains about comments at the end of lines in the class definition. I removed those and wrote some words in the main comment block.

    opened by phil-davis 2
  • Test with PHP 8.0

    Test with PHP 8.0

    1. sort out variables in .travis.yml for selecting to run php-cs-fixer, phpunit and phpstan
    2. Add a matrix entry to run just phpunit on Ubuntu 20.04 "focal" with "nightly" PHP (which is the way to get PHP 8.0 at the moment)
    3. When not running php-cs-fixer, explicitly remove it from composer.json (because php-cs-fixer does not yet support PHP 8.0, so composer cannot sort out dependencies if we have PHP 8.0 and php-cs-fixer 2.* together)
    opened by phil-davis 2
  • Release for PHP 7.4

    Release for PHP 7.4

    Should a release be done to officially record support for PHP 7.4?

    (I don't think any real code needed to be touched, so actually the current release would work fine with PHP 7.4)

    opened by phil-davis 2
  • Use phpunit 9 where possible

    Use phpunit 9 where possible

    https://phpunit.de/announcements/phpunit-9.html

    2nd commit: In Travis, only bother to report/upload coverage if the job actually runs unit tests with coverage enabled.

    opened by phil-davis 2
  • Unit test fails sometimes

    Unit test fails sometimes

    On PHP 7.3 it failed just today:

    $ ./bin/phpunit --verbose --configuration tests/phpunit.xml.dist
    
    PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
    
    Runtime:       PHP 7.3.14 with Xdebug 2.9.1
    
    Configuration: /home/travis/build/sabre-io/cache/tests/phpunit.xml.dist
    
    .............................FF.........S........................ 65 / 72 ( 90%)
    
    .......                                                           72 / 72 (100%)
    
    Time: 12.07 seconds, Memory: 4.00 MB
    
    There were 2 failures:
    
    1) Sabre\Cache\MemcachedTest::testSetExpire
    
    Failed asserting that null matches expected 'bar'.
    
    /home/travis/build/sabre-io/cache/tests/AbstractCacheTest.php:80
    
    2) Sabre\Cache\MemcachedTest::testSetExpireDateInterval
    
    Failed asserting that null matches expected 'bar'.
    
    /home/travis/build/sabre-io/cache/tests/AbstractCacheTest.php:96
    

    But the same unit tests passed on 7.1 7.3 7.4 ???

    It passed when I reran the PHP 7.3 job: https://travis-ci.org/sabre-io/cache/jobs/641984569?utm_medium=notification&utm_source=github_status

    So I guess there is a timing issue somewhere? So there is some timing issue with these unit tests.

    opened by phil-davis 3
  • APC Cache::setMultiple() return must be of the type boolean, array returned

    APC Cache::setMultiple() return must be of the type boolean, array returned

    The APC adapter doesnt implement the interface correctly, it returns directly the result of apcu_store even though the interface calls for boolean result.

    Also it includes the trait MultipleTrait even tough it implements them

    opened by alkemann 0
  • Support APCUIterator

    Support APCUIterator

    Traversable type is converted into a array in userland which can be ineffecient for Iterators providing lots of elements.

    APCU supports a custom type which can be passed into the functions to let this scenario be handled more efficiently.

    http://php.net/manual/en/class.apcuiterator.php

    enhancement 
    opened by staabm 0
Releases(2.0.0)
  • 2.0.0(Aug 23, 2022)

    2.0.0 (2022-08-23)

    • #43 Drop PHP before 7.4 and add type declarations (@phil-davis)

    This major version release adds type declarations supported by PHP 7.4 and later (PHP 8.0 and 8.1). If you have code that extends these classes, then make sure to declare compatible types in that code also. For code that calls into this cache code, make sure to always call with parameters that have the correct declared types.

    Source code(tar.gz)
    Source code(zip)
  • 1.0.4(Jun 24, 2022)

    1.0.4 (2022-06-24)

    • #39 check expiration time in Memory:has() (@Knochenmarc)
    • #38 fix ctype_digit() warnings (@Knochenmarc)
    • #36 Correct some minor typos (@phil-davis)
    • #29 Minor spelling correction (@sdklab007)
    Source code(tar.gz)
    Source code(zip)
  • 1.0.3(Oct 3, 2020)

  • 1.0.2(Oct 3, 2020)

    1.0.2 (2020-10-03)

    • #18 #19 #20 #21 #22: Refactor CI (@phil-davis)
    • #14: Code refactor for phpstan and add support for PHP 7.4 (@phil-davis)
    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(Jul 19, 2019)

Owner
sabre.io
sabre.io
A thin PSR-6 cache wrapper with a generic interface to various caching backends emphasising cache tagging and indexing.

Apix Cache, cache-tagging for PHP Apix Cache is a generic and thin cache wrapper with a PSR-6 interface to various caching backends and emphasising ca

Apix 111 Nov 26, 2022
PSR-6 cache implementation adapting a given PSR-16 instance

PSR-6 cache implementation adapting PSR-16 This package provides a PSR-6 cache instance when you only have a PSR-16 cache at hand. As PSR-6 is more fe

null 1 Oct 15, 2021
This is a Symfony bundle that lets you you integrate your PSR-6 compliant cache service with the framework

PSR-6 Cache bundle This is a Symfony bundle that lets you you integrate your PSR-6 compliant cache service with the framework. It lets you cache your

null 43 Oct 7, 2021
PSR-15 middleware with various cache utilities

middlewares/cache Middleware components with the following cache utilities: CachePrevention Expires Cache Requirements PHP >= 7.2 A PSR-7 http library

Middlewares 15 Oct 25, 2022
Distributed PSR-16 cache implementation for PHP 6 that uses browser cookies to store data

cookiecache Cache beyond the edge with cookies! This library provides a distributed PSR-16 compatible cache implementation for PHP 6 that uses browser

Colin O'Dell 8 Apr 19, 2022
Simple and swift MongoDB abstraction.

Monga A simple and swift MongoDB abstraction layer for PHP 5.4+ What's this all about? An easy API to get connections, databases and collections. A fi

The League of Extraordinary Packages 330 Nov 28, 2022
DataLoaderPhp is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching.

DataLoaderPHP is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching.

Webedia - Overblog 185 Nov 3, 2022
The next-generation caching layer for PHP

The next-generation caching layer for PHP

CacheWerk 115 Dec 25, 2022
Simple cache

Simple cache

Róbert Kelčák 3 Dec 17, 2022
A simple cache library. Implements different adapters that you can use and change easily by a manager or similar.

Desarolla2 Cache A simple cache library, implementing the PSR-16 standard using immutable objects. Caching is typically used throughout an applicatito

Daniel González 129 Nov 20, 2022
A simple cache library. Implements different adapters that you can use and change easily by a manager or similar.

Desarolla2 Cache A simple cache library, implementing the PSR-16 standard using immutable objects. Caching is typically used throughout an applicatito

Daniel González 129 Nov 20, 2022
Simple artisan command to debug your redis cache. Requires PHP 8.1 & Laravel 9

?? php artisan cache:debug Simple artisan command to debug your redis cache ?? Installation You can install the package via composer: composer require

Juan Pablo Barreto 19 Sep 18, 2022
The place to keep your cache.

Stash - A PHP Caching Library Stash makes it easy to speed up your code by caching the results of expensive functions or code. Certain actions, like d

Tedious Developments 944 Jan 4, 2023
PHP cache library, with adapters for e.g. Memcached, Redis, Couchbase, APC(u), SQL and additional capabilities (e.g. transactions, stampede protection) built on top.

Donate/Support: Documentation: https://www.scrapbook.cash - API reference: https://docs.scrapbook.cash Table of contents Installation & usage Adapters

Matthias Mullie 295 Nov 28, 2022
Cache slam defense using a semaphore to prevent dogpile effect.

metaphore PHP cache slam defense using a semaphore to prevent dogpile effect (aka clobbering updates, stampending herd or Slashdot effect). Problem: t

Przemek Sobstel 102 Sep 28, 2022
Doctrine Cache component

Doctrine Cache Cache component extracted from the Doctrine Common project. Documentation This library is deprecated and will no longer receive bug fix

Doctrine 7.6k Jan 3, 2023
LRU Cache implementation in PHP

PHP LRU Cache implementation Intro WTF is a LRU Cache? LRU stands for Least Recently Used. It's a type of cache that usually has a fixed capacity and

Rogério Vicente 61 Jun 23, 2022
More Than Just a Cache: Redis Data Structures

More Than Just a Cache: Redis Data Structures Redis is a popular key-value store, commonly used as a cache or message broker service. However, it can

Andy Snell 2 Oct 16, 2021