Commit cd0b765b authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Plus de cache : aucun impact sur perfs

parent 4e9f533f
Loading
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -32,9 +32,6 @@
    "require": {
        "php": "^8.0",
        "doctrine/common": "^3.2",
        "laminas/laminas-cache": "^3.1|^4.1",
        "laminas/laminas-cache-storage-deprecated-factory": "^1.0",
        "laminas/laminas-cache-storage-adapter-memory": "^2.0",
        "laminas/laminas-eventmanager": "^3.4",
        "laminas/laminas-http": "^2.15",
        "laminas/laminas-mvc": "^3.3",
+0 −15
Original line number Diff line number Diff line
@@ -32,25 +32,10 @@ return [

        // Template name for the unauthorized strategy
        'template'              => 'error/403',

        // cache options have to be compatible with Laminas\Cache\StorageFactory::factory
        'cache_options'         => [
            'adapter'   => [
                'name' => 'memory',
            ],
            'plugins'   => [
                'serializer',
            ]
        ],

        // Key used by the cache for caching the acl
        'cache_key'             => 'bjyauthorize_acl'
    ],

    'service_manager' => [
        'factories' => [
            'BjyAuthorize\Cache'                    => 'BjyAuthorize\Service\CacheFactory',
            'BjyAuthorize\CacheKeyGenerator'        => 'BjyAuthorize\Service\CacheKeyGeneratorFactory',
            'BjyAuthorize\Config'                   => 'BjyAuthorize\Service\ConfigServiceFactory',
            'BjyAuthorize\Guards'                   => 'BjyAuthorize\Service\GuardsServiceFactory',
            'BjyAuthorize\RoleProviders'            => 'BjyAuthorize\Service\RoleProvidersServiceFactory',
+4 −14
Original line number Diff line number Diff line
@@ -15,13 +15,13 @@ use BjyAuthorize\Provider\Identity\ProviderInterface as IdentityProvider;
use BjyAuthorize\Provider\Resource\ProviderInterface as ResourceProvider;
use BjyAuthorize\Provider\Role\ProviderInterface as RoleProvider;
use BjyAuthorize\Provider\Rule\ProviderInterface as RuleProvider;
use Laminas\Cache\Storage\StorageInterface;
use Laminas\Permissions\Acl\Acl;
use Laminas\Permissions\Acl\Exception\InvalidArgumentException;
use Laminas\Permissions\Acl\Resource\GenericResource;
use Laminas\Permissions\Acl\Resource\ResourceInterface;
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\Session\Container as SessionContainer;
use UnicaenApp\Util;

/**
@@ -80,6 +80,8 @@ class Authorize
     */
    protected $config;

    protected SessionContainer $sessionContainer;

    /**
     * Loading...
     *
@@ -95,6 +97,7 @@ class Authorize
    {
        $this->config         = $config;
        $this->serviceLocator = $serviceLocator;
        $this->sessionContainer = new SessionContainer( self::class );
        $that                 = $this;
        $this->loaded         = function () use ($that) {
            $that->load();
@@ -272,20 +275,7 @@ class Authorize
        $this->loaded = null;
        $this->loading = true;

        /** @var $cache StorageInterface */
        $cache      = $this->serviceLocator->get('BjyAuthorize\Cache');

        /** @var $cacheKeyGenerator callable */
        $cacheKeyGenerator  = $this->serviceLocator->get('BjyAuthorize\CacheKeyGenerator');
        $cacheKey           = $cacheKeyGenerator();

        $success    = false;
        $this->acl  = $cache->getItem($cacheKey, $success);

        if (!($this->acl instanceof Acl) || !$success) {
        $this->loadAcl();
            $cache->setItem($cacheKey, $this->acl);
        }

        $this->setIdentityProvider($this->serviceLocator->get('BjyAuthorize\Provider\Identity\ProviderInterface'));

+0 −34
Original line number Diff line number Diff line
<?php
/**
 * BjyAuthorize Module (https://github.com/bjyoungblood/BjyAuthorize)
 *
 * @link https://github.com/bjyoungblood/BjyAuthorize for the canonical source repository
 * @license http://framework.zend.com/license/new-bsd New BSD License
 */

namespace BjyAuthorize\Service;

use Psr\Container\ContainerInterface;
use Laminas\Cache\StorageFactory;
use Laminas\ServiceManager\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;

/**
 * Factory for building the cache storage
 *
 * @author Christian Bergau <cbergau86@gmail.com>
 */
class CacheFactory implements FactoryInterface
{
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        return $this->__invoke($serviceLocator, '?');
    }

    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
    {
        $options = $container->get('BjyAuthorize\Config');

        return StorageFactory::factory($options['cache_options']);
    }
}
+0 −36
Original line number Diff line number Diff line
<?php
/**
 * BjyAuthorize Module (https://github.com/bjyoungblood/BjyAuthorize)
 *
 * @link https://github.com/bjyoungblood/BjyAuthorize for the canonical source repository
 * @license http://framework.zend.com/license/new-bsd New BSD License
 */

namespace BjyAuthorize\Service;

use Psr\Container\ContainerInterface;
use Laminas\ServiceManager\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;

/**
 * Factory for building a cache key generator
 *
 * @author Steve Rhoades <sedonami@gmail.com>
 */
class CacheKeyGeneratorFactory implements FactoryInterface
{
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        return $this->__invoke($serviceLocator, '?');
    }

    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
    {
        $config     = $container->get('BjyAuthorize\Config');
        $cacheKey   = empty($config['cache_key']) ? 'bjyauthorize_acl' : (string) $config['cache_key'];

        return function () use ($cacheKey) {
            return $cacheKey;
        };
    }
}
Loading