New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache Util Package #121

Closed
ragboyjr opened this Issue Dec 28, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@ragboyjr

ragboyjr commented Dec 28, 2017

It would be nice if the php-cache ecosystem had a util package that implemented utility functions on top of the psr-6 and psr-16 interfaces.

An example function would be something like.

<?php

namespace Cache\Util;

use Psr\SimpleCache\CacheInterface;

function remember(CacheInterface $cache, $key, $ttl, callable $fetch) {
    $res = $cache->get($key);
    if ($res) {
        return $res;
    }

    $res = $fetch();
    $cache->set($key, $value, $ttl);
    return $res;
}

Usage:

$cache = new ArrayCache();
$res = Cache\Util\remember($cache, 'key', 3600, function() {
    // return some expensive query here.
});

I can't think of any other utility functions, but that is a very common pattern when accessing cache items and it seems like utility functions would fit well with the Cache packages.

@Nyholm

This comment has been minimized.

Show comment
Hide comment
@Nyholm

Nyholm Dec 28, 2017

Member
Member

Nyholm commented Dec 28, 2017

@ragboyjr

This comment has been minimized.

Show comment
Hide comment
@ragboyjr

ragboyjr Dec 28, 2017

You got it!

ragboyjr commented Dec 28, 2017

You got it!

@ragboyjr ragboyjr referenced this issue Dec 28, 2017

Merged

Added Cache Util Package #206

0 of 1 task complete
@ragboyjr

This comment has been minimized.

Show comment
Hide comment
@ragboyjr

ragboyjr commented Dec 28, 2017

@Nyholm done.

@prisis prisis closed this Feb 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment