entrust: This cache store does not support tagging.

Happend after update to 5.2.

Not sure if this has something to do with entrust but in the list I see that this issue has something to do with Repository->tags(‘role_user’) and Cache::tags(‘role_user’) in EntrustUserTrait.php line 29

BadMethodCallException in C:\wamp\www\baseapp\vendor\laravel\framework\src\Illuminate\Cache\Repository.php line 380:
This cache store does not support tagging.
in Repository.php line 380
at Repository->tags('role_user')
at call_user_func_array(array(object(Repository), 'tags'), array('role_user')) in CacheManager.php line 296
at CacheManager->__call('tags', array('role_user')) in Facade.php line 216
at CacheManager->tags('role_user') in Facade.php line 216
at Facade::__callStatic('tags', array('role_user')) in EntrustUserTrait.php line 29
at Cache::tags('role_user') in EntrustUserTrait.php line 29
at User->save() in EloquentUserProvider.php line 78

Anyone else had this one? And ideas?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 46
  • Comments: 75 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Yes, Laravel file and database drivers doesn’t support tags. What you can do to while developing is change the driver to array in your .env file. CACHE_DRIVER=array

in your .env file change to cache array

CACHE_DRIVER=array

and dont forget to run

php artisan config:cache

WARNING: is not a permanent solution, just disables caching. So while Cache methods will work, no data will actually be available between requests. You better configure memcached or redis ( thanks @CaptainHypertext )

I changed to composer to “zizaco/entrust”: “dev-laravel-5” and it solved it.

Blade directives

@if(Entrust::hasRole('admin'))
    ....
@endif

working but

@role('admin'))
    <div>This is visible to users with the admin role. Gets translated to role('admin')</div>
@endrole

not.

should i change both settings? .env file

CACHE_DRIVER=array

and in config/cache.php

'default' => env('CACHE_DRIVER', 'array'),

I have tried for all still i am getting error regarding cache

BadMethodCallException in Repository.php line 367: This cache store does not support tagging.

“zizaco/entrust”: “dev-laravel-5” will solve this problem

Just change: “zizaco/entrust”: “5.2.x-dev” TO “zizaco/entrust”: “dev-master”

then solved.

“dev-master” have Merged pjmartorell:fix-cache-tags

Changing cache driver to array: CACHE_DRIVER=array fixed this issue for me, I am also creating user and attaching role directly after and have no issue. I’m using laravel 5.2.

It is possible to use apc, memcached or redis.

CACHE_DRIVER=apc CACHE_DRIVER=memcached CACHE_DRIVER=redis

Moreover, they are all preconfigured in homestead environment.

I am still the same error, even after update .env file and change to composer to “zizaco/entrust”: “dev-laravel-5” 😦

@thanhdevapp You can either fork it or use it temporary until changes/PR are merged into this package.

Add this to your composer.json

  "repositories": [
    {
      "type": "vcs",
      "url": "git@github.com:marcoraddatz/entrust.git"
    }
  ],
  "require": {
    "marcoraddatz/entrust": "dev-master",
  }

@pjmartorell: Thanks for providing your solution! Yes, the exceptions are fixed, but a cache for non-taggable providers is still missing.

Right now, when using array or file caches, Entrust will query the DB every time a permission/role is requested—even though it’s exactly the same query. To avoid that, I extended your code a bit, so that they are at least cached for the request.

Using array as a cache driver works, but it’s an workaround and should not be used in production. Any other solution to don’t use array as a cache driver? thanks in advance.

@marcoraddatz @thanhdevapp @kickthemooon All these errors/alerts are fixed in branch master. Do a require of "zizaco/entrust": "dev-master" to install it. You can check the changes done to solve it in https://github.com/Zizaco/entrust/pull/547.

This cache feature I guess is perfect for big/performant systems.

But for something quick I just switched to https://github.com/caffeinated/shinobi

Because is quicker to configure and already has a GUI and I’m lazy.

I think I found the issue, maybe.

Note: Cache tags are not supported when using the file or database cache drivers. Furthermore, when using multiple tags with caches that are stored "forever", performance will be best with a driver such as memcached, which automatically purges stale records.

and here is the entrust trait:

//Big block of caching functionality.
    public function cachedRoles()
    {
        $userPrimaryKey = $this->primaryKey;
        $cacheKey = 'entrust_roles_for_user_'.$this->$userPrimaryKey;
        return Cache::tags(Config::get('entrust.role_user_table'))->remember($cacheKey, Config::get('cache.ttl'), function () {
            return $this->roles()->get();
        });
    }
    public function save(array $options = [])
    {   //both inserts and updates
        parent::save($options);
        Cache::tags(Config::get('entrust.role_user_table'))->flush();
    }
    public function delete(array $options = [])
    {   //soft or hard
        parent::delete($options);
        Cache::tags(Config::get('entrust.role_user_table'))->flush();
    }
    public function restore()
    {   //soft delete undo's
        parent::restore();
        Cache::tags(Config::get('entrust.role_user_table'))->flush();
    }

Could this be the issue and how can it be dealt with?

See #422 for a fix that doesnt involve changing the cache driver. It tells you to use the following version “dev-laravel-5” in your composer.json

I’m having issues with this in 5.2 when I moved to production. Is there a solution for production?

**EDIT: Nevermind. The documentation states that tagging does not work with file or database cache. I changed to memcached and it worked fine.**

Switching to array is not a solution if you use the DB for a cache in production.

I changed to composer.json to “zizaco/entrust”: “dev-laravel-5” as well as updated my .env file and config/cache.php file to be CACHE_DRIVER array. Problem was solved for me

.env CACHE_DRIVER=array is worked for me

CACHE_DRIVER=array is just a temporary fix for development, isn’t it? I’d like to keep using the file cache driver on the production site but that isn’t working right now. Any news on this issue?

Occured to me when registering a new user on a new L5.2 installation with "zizaco/entrust": "5.2.x-dev",

I have CACHE_DRIVER=array and works fine !!! However I want to use CACHE_DRIVER=memcached. I’ve tried to add on the .env file the memcached but it doesn’t work. Keep saying Class 'Memcached' not found. I’ve tried to download memcached but I dont have apt-get in my shared server. What can I do ? Anyone can help me ?

Try to config cache ( php artisan config:cache ) for laravel

CACHE_DRIVER=array work for me on v5.3.24 remember to restart your web server.

@marcoraddatz Nice, but if there is a file store defined, with your implementation, you are forcing the user to use an ‘array’ store.

@eduardoarandah, @CaptainHypertext: As far as I know doesn’t array disable the cache, but restricts it to a single request only.

I just forked the project and played around a bit. Following code reduced my queries dramatically (40+ queries to 8):

/**
 * Big block of caching functionality.
 *
 * @return \Illuminate\Database\Eloquent\Collection
 */
public function cachedPermissions()
{
    $rolePrimaryKey = $this->primaryKey;
    $cacheKey       = 'entrust_permissions_for_role_' . $this->$rolePrimaryKey;

    if (Cache::getStore() instanceof TaggableStore) {
        return Cache::tags(Config::get('entrust.permission_role_table'))->remember($cacheKey, Config::get('cache.ttl', 60), function () {
            return $this->perms()->get();
        });
    }
    else {
        return Cache::store('array')->remember($cacheKey, 0, function () {
            return $this->perms()->get();
        });
    }
}

and

/**
 * Big block of caching functionality.
 *
 * @return \Illuminate\Database\Eloquent\Collection
 */
public function cachedRoles()
{
    $userPrimaryKey = $this->primaryKey;
    $cacheKey       = 'entrust_roles_for_user_' . $this->$userPrimaryKey;

    if (Cache::getStore() instanceof TaggableStore) {
        return Cache::tags(Config::get('entrust.role_user_table'))->remember($cacheKey, Config::get('cache.ttl', 60), function () {
            return $this->roles()->get();
        });
    }
    else {
        return Cache::store('array')->remember($cacheKey, 0, function () {
            return $this->roles()->get();
        });
    }
}

Full code is at https://github.com/marcoraddatz/entrust – will provide it soon via packagist.

Ultimately I made the decision that the best option was to start using memcached.

I m facing problem while i am registering new user and setting role for that user in controller

/**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        $user=User::create([
            'firstname' => $data['firstname'],
            'lastname' => $data['lastname'],
            'gender' => $data['gender'],
            'birthdate' => date("Y-m-d", strtotime($data['birthdate'])),
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
            'temple' => $data['temple'],
            'refname' => $data['refname'],
            'refcontact' => $data['refcontact'],
        ]);
       $user->attachRole(2); // parameter can be an Role object, array, or id

        return $user;

    }