8000 Added an ability to set a default invalidation method for the pool by Finesse · Pull Request #407 · tedious/Stash · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added an ability to set a default invalidation method for the pool #407

8000
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 21, 2022
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/pr_tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on: [push]
on: [push, pull_request]
env:
IS_GITHUB: "true"

Expand Down
11 changes: 11 additions & 0 deletions src/Stash/Interfaces/PoolInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ public function getNamespace();
*/
public function setLogger($logger);

/**
* Sets the default cache invalidation method for items created by this pool object.
*
* @see Stash\Invalidation
*
* @param int $invalidation A Stash\Invalidation constant
* @param mixed $arg First argument for invalidation method
* @param mixed $arg2 Second argument for invalidation method
*/
public function setInvalidationMethod($invalidation, $arg = null, $arg2 = null);

/**
* Forces any save-deferred objects to get flushed to the backend drivers.
*
Expand Down
34 changes: 34 additions & 0 deletions src/Stash/Pool.php
8000
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ class Pool implements PoolInterface
*/
protected $namespace;

/**
* The default cache invalidation method for items created by this pool object.
*
* @var int
*/
protected $invalidationMethod = Invalidation::PRECOMPUTE;

/**
* Argument 1 for the default cache invalidation method
*
* @var mixed
*/
protected $invalidationArg1 = null;

/**
* Argument 2 for the default cache invalidation method
*
* @var mixed
*/
protected $invalidationArg2 = null;

/**
* The constructor takes a Driver class which is used for persistent
* storage. If no driver is provided then the Ephemeral driver is used by
Expand Down Expand Up @@ -120,6 +141,7 @@ public function getItem($key)
$item = new $this->itemClass();
$item->setPool($this);
$item->setKey($key, $namespace);
$item->setInvalidationMethod($this->invalidationMethod, $this->invalidationArg1, $this->invalidationArg2);

if ($this->isDisabled) {
$item->disable();
Expand Down Expand Up @@ -308,6 +330,18 @@ public function setLogger($logger)
return true;
}

/**
* {@inheritdoc}
*/
public function setInvalidationMethod($invalidation = Invalidation::PRECOMPUTE, $arg = null, $arg2 = null)
{
$this->invalidationMethod = $invalidation;
$this->invalidationArg1 = $arg;
$this->invalidationArg2 = $arg2;

return true;
}

/**
* Logs an exception with the Logger class, if it exists.
*
Expand Down
13 changes: 13 additions & 0 deletions tests/Stash/Test/AbstractPoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Stash\Test;

use Stash\Exception\InvalidArgumentException;
use Stash\Invalidation;
use Stash\Pool;
use Stash\Driver\Ephemeral;
use Stash\Test\Stubs\LoggerStub;
Expand Down Expand Up @@ -348,6 +349,18 @@ public function testLoggerPurge()
$this->assertEquals('critical', $logger->lastLevel, 'Exceptions logged as critical.');
}

public function testSetInvalidationMethod()
{
$pool = $this->getTestPool();

$pool->setInvalidationMethod(Invalidation::OLD, 'test1', 'test2');
$item = $pool->getItem('test/item');

$this->assertAttributeEquals(Invalidation::OLD, 'invalidationMethod', $item, 'Pool sets Item invalidation constant.');
$this->assertAttributeEquals('test1', 'invalidationArg1', $item, 'Pool sets Item invalidation argument 1.');
$this->assertAttributeEquals('test2', 'invalidationArg2', $item, 'Pool sets Item invalidation argument 2.');
}

/**
* @return \Stash\Pool
*/
Expand Down
5 changes: 5 additions & 0 deletions tests/Stash/Test/Stubs/PoolGetDriverStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public function setLogger($logger)
return false;
}

public function setInvalidationMethod($invalidation, $arg = null, $arg2 = null)
{
return false;
}

public function hasItem($key)
{
return false;
Expand Down
0