-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16714 from niden-code/T16696-cache-lifetime
T16696 cache lifetime
- Loading branch information
Showing
7 changed files
with
98 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
use function ob_get_contents; | ||
use function ob_start; | ||
use function outputDir; | ||
use function sleep; | ||
use function uniqid; | ||
use function var_dump; | ||
|
||
|
@@ -216,6 +217,76 @@ public function mvcModelFindResultsetSecondIteration(DatabaseTester $I) | |
} | ||
} | ||
|
||
/** | ||
* Tests Phalcon\Mvc\Model :: find() | ||
* | ||
* @author Phalcon Team <[email protected]> | ||
* @since 2020-02-01 | ||
* | ||
* @group mysql | ||
* @issue 16696 | ||
*/ | ||
public function testMvcModelFindWithCacheLifetimeFromCacheService(DatabaseTester $I): void | ||
{ | ||
/** @var PDO $connection */ | ||
$connection = $I->getConnection(); | ||
|
||
$migration = new ObjectsMigration($connection); | ||
$migration->insert(1, 'random data', 1); | ||
|
||
$options = [ | ||
'defaultSerializer' => 'Json', | ||
'lifetime' => 2, | ||
'prefix' => 'data-', | ||
]; | ||
|
||
/** | ||
* Models Cache setup. Lifetime is 2 seconds | ||
*/ | ||
$serializerFactory = new SerializerFactory(); | ||
$adapterFactory = new AdapterFactory($serializerFactory); | ||
$adapter = $adapterFactory->newInstance('apcu', $options); | ||
$cache = new Cache($adapter); | ||
|
||
$this->container->setShared('modelsCache', $cache); | ||
|
||
/** | ||
* Get the records (should cache the resultset) | ||
*/ | ||
$data = Objects::find( | ||
[ | ||
'cache' => [ | ||
'key' => 'my-cache', | ||
], | ||
] | ||
); | ||
|
||
$I->assertEquals(1, count($data)); | ||
|
||
$record = $data[0]; | ||
$I->assertEquals(1, $record->obj_id); | ||
$I->assertEquals('random data', $record->obj_name); | ||
|
||
/** | ||
* Get the models cache | ||
*/ | ||
$modelsCache = $this->container->get('modelsCache'); | ||
|
||
$exists = $modelsCache->has('my-cache'); | ||
$I->assertTrue($exists); | ||
|
||
/** | ||
* Wait for 3 seconds for the cache to expire | ||
*/ | ||
sleep(3); | ||
|
||
/** | ||
* Get the data now from the cache - expired | ||
*/ | ||
$data = $modelsCache->get('my-cache'); | ||
$I->assertNull($data); | ||
} | ||
|
||
/** | ||
* Tests Phalcon\Mvc\Model :: find() - with cache/exception | ||
* | ||
|