matthiasmullie / scrapbook

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.
https://www.scrapbook.cash
MIT License
315 stars 27 forks source link

Is there Symfony bundle for Scrapbook? #8

Closed sunra closed 7 years ago

sunra commented 8 years ago

in code? in plans?

matthiasmullie commented 8 years ago

Hey @sunra. There is none at the moment, and I didn't have any plans to create one (yet).

You wouldn't happen to be interested in building one? I'd be happy to help out!

rlataguerra commented 8 years ago

a symfony bundle would be great

radoslavius commented 8 years ago

no need imho

yml:

parameters:
    cache_sqlite_db: 'sqlite:%kernel.root_dir%/../var/cache/%kernel.environment%/cache.db'

services:
    cache.db:
        class: PDO
        arguments: ["%cache_sqlite_db%"]

    cache.adapter:
        class: MatthiasMullie\Scrapbook\Adapters\SQLite
        arguments: ["@cache.db"]

    cache.pool:
        class: MatthiasMullie\Scrapbook\Psr6\Pool
        arguments: ["@cache.adapter"]

    cache.taggablepool:
        class: MatthiasMullie\Scrapbook\Psr6\Taggable\Pool
        arguments: ["@cache.pool"]

usage in controller:

$pool = $this->get('cache.taggablepool');
$item = $pool->getItem('your_key');
if (!is_null($item->get())) {
    $data = $item->get();
}
else {
    $data = // do something to cache
    $item->set($data);
    $item->expiresAfter(600); //cache for 10 minutes
    $pool->save($item);
}
matthiasmullie commented 7 years ago

I agree with @radoslavius that this is not really needed. All features are easy to "enable" just by wrapping them inside one another, from the YML file. Here's another example: https://github.com/forkcms/forkcms/blob/master/app/config/config.yml#L89

If anyone feels a Symfony bundle is useful and is willing to create one, I wouldn't mind helping out. But for now, I'm closing this :)