in config services.yml, how to cache use¿?

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
DevMakoto
Registered User
Posts: 65
Joined: Tue Jun 23, 2015 3:38 pm
Name: Carlos Mayorga
Contact:

in config services.yml, how to cache use¿?

Post by DevMakoto » Sun Jan 22, 2017 10:12 pm

in services.yml

Code: Select all

services:
    devmakoto.demo.core:
        class: devmakoto\demo\core\demo
        arguments:
            - '@config'
            - '@template'
            - '@cache'
in demo.php

construct

Code: Select all

public function __construct(\phpbb\config\config $config, \phpbb\template\template $template, \phpbb\cache\service $cache)
in file

Code: Select all

$data = 'demo';
$this->cache->put('_name_demo', $data, 300);
but, use get

Code: Select all

$this->cache->get('_name_demo')
return false :(

Where is the error?
I use phpstorm but before I did not have this problem

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3697
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: in config services.yml, how to cache use¿?

Post by kasimi » Sun Jan 22, 2017 10:20 pm

@cache is the phpbb\cache\cache_service class (https://github.com/phpbb/phpbb/blob/3.1 ... es.yml#L21).

I think what you want is the @cache.driver service (implements \phpbb\cache\driver\driver_interface) (https://github.com/phpbb/phpbb/blob/3.1 ... es.yml#L30) :)

User avatar
DevMakoto
Registered User
Posts: 65
Joined: Tue Jun 23, 2015 3:38 pm
Name: Carlos Mayorga
Contact:

Re: in config services.yml, how to cache use¿?

Post by DevMakoto » Sun Jan 22, 2017 10:24 pm

In another extension I use the same code for the cache and I do not have the error
u-u

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3697
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: in config services.yml, how to cache use¿?

Post by kasimi » Sun Jan 22, 2017 10:27 pm

You could use @cache indeed but you'd have to get the driver from it first:

Code: Select all

$this->cache->get_driver()->put('_name_demo', $data, 300);

User avatar
DevMakoto
Registered User
Posts: 65
Joined: Tue Jun 23, 2015 3:38 pm
Name: Carlos Mayorga
Contact:

Re: in config services.yml, how to cache use¿?

Post by DevMakoto » Sun Jan 22, 2017 10:33 pm

It seems to be a bug in libraries, I use customapi libraries for example and if I create an extension with the package name "customapi" it causes me error

Post Reply

Return to “Extension Writers Discussion”