Laravel + Wincache on MS Azure: Not storing values

*爱你&永不变心* 提交于 2021-02-19 05:32:38

问题


I am running a PHP application on azure and am experiencing some strange behaviour: This snippet runns in a Console command:

public function fire(Illuminate\Contracts\Cache\Repository $cache) {
    $cache->forever('someKey', 'someValue');

    var_dump($cache->get('someKey'));
}

The output is:

NULL

Accessing the value through wincache_ucache_get after executing the command also returns NULL (with prefix and without). Has anyone a clue on this?


P.S.: As per phpinfo() the wincache usercache is enabled: wincache.ucenabled On


After some more debugging i know some more facts:

In an isolated php file wincache_ucache_set and wincache_ucache_get work perfectly.

However, the call to wincache_ucache_set in Illuminate\Cache\WinCacheStore returns false.


回答1:


As there is a setting wincache.enablecli in php runtime to control whether wincache is enabled in CLI mode.

By default it is set 0 so that the function wincache_ucache_set() cannot work in artisan commands.

You can refer to the guide on Azure official about Changing PHP_INI_SYSTEM configuration settings, to set the

wincache.enablecli=1

in additional php configuration settings.

Then the following code snippet should work well:

public function fire()
    {
        wincache_ucache_set('foo','goo',0);
        var_dump(wincache_ucache_get('foo')); 
    }

or like:

use Cache;
public function fire()
    {

        Cache::forever('someKey', 'someValue');
        var_dump(Cache::get('someKey'));

    }


来源:https://stackoverflow.com/questions/35318872/laravel-wincache-on-ms-azure-not-storing-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!