php-casbin / laravel-authz

An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.
Apache License 2.0
272 stars 46 forks source link

What if I want to get a new instance? #32

Closed guoliang1994 closed 2 years ago

guoliang1994 commented 2 years ago

When I use it in workerman, the data I get is always the same,What should I do if I want to get a new instance.

 $policy = Enforcer::getPolicy();

Even if my database has been updated, this method always returns the old data,

The following method is singleton mode

    /**
     * Attempt to get the enforcer from the local cache.
     *
     * @param string $name
     *
     * @return \Casbin\Enforcer
     *
     * @throws \InvalidArgumentException
     */
    public function guard($name = null)
    {
        $name = $name ?: $this->getDefaultGuard();

        if (!isset($this->guards[$name])) {
            $this->guards[$name] = $this->resolve($name);
        }
        return $this->guards[$name];
    }
hsluoyz commented 2 years ago

@basakest @techoner

guoliang1994 commented 2 years ago

@techoner @basakest

leeqvip commented 2 years ago

@guoliang1994 Workman is multi-process, we need to use watcher to synchronize : https://github.com/php-casbin/workerman-redis-watcher