public function testSameIdentifierTwiceTime()
 {
     $path = dirname(dirname(dirname(__FILE__))) . '/tests/_drafts/test-cache-keyed.cdb';
     try {
         $cacheRead = new \PhpDbaCache\Cache($path, 'cdb', 'r');
     } catch (\RuntimeException $e) {
         $this->markTestSkipped($e->getMessage());
     }
     //check if data replaced.
     $this->assertEquals('data', $cacheRead->get('key'));
     $cacheRead->closeDba();
 }
 public function testPutSameIdentifierTwiceTime()
 {
     $path = dirname(dirname(dirname(__FILE__))) . '/tests/_drafts/test-cache-keyed.cdb';
     try {
         $cacheMake = new \PhpDbaCache\Cache($path, 'cdb_make', 'n');
     } catch (\RuntimeException $e) {
         $this->markTestSkipped($e->getMessage());
     }
     // first insert.
     $this->assertTrue($cacheMake->put('key', 'data'));
     // replace instead of insert.
     $this->assertTrue($cacheMake->put('key', 'data-2'));
     // for read we close the handler.
     $cacheMake->closeDba();
 }
 public function testHandlingWithSimpleXMLElementIntoFlatfileHandler()
 {
     $identifier = md5(uniqid());
     // make a xml-file of 1000 nodes.
     $string = "<?xml version='1.0'?>\n        <document>";
     for ($i = 1; $i <= 100; $i++) {
         $string .= "<item>\n\t\t\t <title>Let us cache</title>\n\t\t\t <from>Joe</from>\n\t\t\t <to>Jane</to>\n\t\t\t <body>Some content here</body>\n                 </item>";
     }
     $string .= "</document>";
     $simplexml = simplexml_load_string($string, 'SimpleXMLElement', LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_NONET);
     $path = dirname(__FILE__) . '/_drafts/test-cache-with-simplexml.flatfile';
     try {
         $cache = new \PhpDbaCache\Cache($path);
     } catch (\RuntimeException $e) {
         $this->markTestSkipped($e->getMessage());
     }
     $cache->put($identifier, $simplexml);
     $object_from_cache = $cache->get($identifier);
     $cache->closeDba();
     $this->assertEquals($simplexml->asXML(), $object_from_cache->asXML());
     @unlink($path);
 }
<?php

if (PHP_SAPI != 'cli') {
    die('no trespass! call the administrator!');
}
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'bootstrap.php';
set_time_limit(0);
ini_set("memory_limit", "-1");
function generateAddressFixture()
{
    return array(substr(str_shuffle('abcdefghijklmnopqrstuvwxyz'), 0, rand(8, 16)), sprintf('%05d', rand(1, 99999)), substr(str_shuffle('abcdefghijklmnopqrstuvwxyz'), 0, rand(8, 16)), substr(str_shuffle('abcdefghijklmnopqrstuvwxyz'), 0, 2));
}
$db = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'app.db4';
$cache = new \PhpDbaCache\Cache($db, 'db4', 'c-', true);
for ($key = 0; $key < 1000000; $key++) {
    print_r($value = generateAddressFixture());
    print 'SAVED=' . (int) $cache->put($key, $value, rand(1, 21600)) . PHP_EOL;
    sleep(rand(0, 1));
}
$cache->closeDba();
die('END');
示例#5
0
 /**
  * Tests support for CDB - Tiny Constant Database.
  * CDB can not be deleted - clear garbage manually.
  */
 public function testCleanGarbageCollectionOnCdbHandler()
 {
     $path = dirname(dirname(__FILE__)) . '/tests/_drafts/test-cache-cdb2.cdb';
     // create cdb-handler to write.
     try {
         $cacheMake = new \Cache($path, 'cdb_make', 'n');
     } catch (\RuntimeException $e) {
         $this->markTestSkipped($e->getMessage());
     }
     $this->assertInstanceOf('\\PhpDbaCache\\Cache', $cacheMake);
     $testIdentifier1 = md5('ZipArchive' . time());
     $testIdentifier2 = md5('XMLReader' . time());
     $this->assertTrue($cacheMake->put($testIdentifier1, new \ZipArchive()));
     $this->assertTrue($cacheMake->put($testIdentifier2, new \XMLReader()));
     // CacheGarbageCollector has no effect.
     $sweep = new \PhpDbaCache\Sweep($cacheMake);
     $sweep->all();
     // deleting has no effect.
     $cacheMake->delete($testIdentifier1);
     $cacheMake->delete($testIdentifier2);
     // for read we close the handler.
     $cacheMake->closeDba();
     // create cdb-handler to read.
     try {
         $cacheRead = new \PhpDbaCache\Cache($path, 'cdb', 'r');
     } catch (\RuntimeException $e) {
         $this->markTestSkipped($e->getMessage());
     }
     $this->assertTrue($cacheRead->has($testIdentifier1));
     $this->assertTrue($cacheRead->has($testIdentifier2));
     $this->assertInstanceOf('\\PhpDbaCache\\ZipArchive', $cacheRead->get($testIdentifier1));
     $this->assertInstanceOf('\\PhpDbaCache\\XMLReader', $cacheRead->get($testIdentifier2));
     $cacheRead->closeDba();
 }