Exemplo n.º 1
0
 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);
 }
Exemplo n.º 3
0
<?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');