Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
'cache' => null,
'routes' => array(
),
'priority' => 1,
),
);
11 changes: 8 additions & 3 deletions src/SlmCache/Listener/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
class Cache extends AbstractListenerAggregate
{
protected $cache_prefix = 'slm_cache_';
protected $cache_priority = 1;

protected $match;
protected $serviceLocator;
Expand All @@ -65,15 +66,19 @@ public function __construct(ServiceLocatorInterface $sl)
if (isset($config['slm_cache']['cache_prefix'])) {
$this->cache_prefix = $config['slm_cache']['cache_prefix'];
}
}

if (isset($config['slm_cache']['priority'])) {
$this->cache_priority = $config['slm_cache']['priority'];
}
}

/**
* {@inheritDoc}
*/
public function attach(EventManagerInterface $events)
{
$events->attach(MvcEvent::EVENT_ROUTE, array($this, 'matchRoute'));
$events->attach(MvcEvent::EVENT_FINISH, array($this, 'saveRoute'));
$events->attach(MvcEvent::EVENT_ROUTE, array($this, 'matchRoute'), $this->cache_priority);
$events->attach(MvcEvent::EVENT_FINISH, array($this, 'saveRoute'), $this->cache_priority);
}

public function matchRoute(MvcEvent $e)
Expand Down
39 changes: 39 additions & 0 deletions tests/SlmCacheTest/Listener/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,43 @@ public function testCachePrefixIsDefault()
PHPUnit_Framework_Assert::readAttribute($listener, 'cache_prefix')
);
}

public function testCachePriorityIsUserDefined()
{
$config = array(
'slm_cache' => array(
'priority' => 200
)
);

$sl = new ServiceManager;
$sl->setService('Config', $config);

$listener = new CacheListener($sl);

$this->assertEquals(
$config['slm_cache']['priority'],
PHPUnit_Framework_Assert::readAttribute($listener, 'cache_priority')
);
}

public function testCachePriorityIsDefault()
{
$config = array(
'slm_cache' => array(
'cache' => array()
)
);

$sl = new ServiceManager;
$sl->setService('Config', $config);

$listener = new CacheListener($sl);

$this->assertEquals(
1,
PHPUnit_Framework_Assert::readAttribute($listener, 'cache_priority')
);
}

}