
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 1.26 KB | hits: 21 | expires: Never
Usage of the classes for permanent storage:
Použití classes pro permanentní úložiště:
<?php
$journal = new AppFileJournal(DATA_DIR . '/user/');
$driver = new AppFileStorage(DATA_DIR . '/user/', $journal);
// Get the cache tags
$tags = array();
$tags[] = self::USERID . self::SEPARATOR . $data->user->id;
$tags[] = self::TIMESTAMP . self::SEPARATOR . $data->timestamp;
// Get the key
do {
$key = sha1(uniqid(time()));
$has = $driver->read($key);
} while(!empty($has));
// Store the metrics into cache
return $driver->write($key, $data, array(\Nette\Caching\Cache::TAGS => $tags));
?>
Searching within the storage:
Vyhledávání v rámci storage:
<?php
class Mine {
const USERID = 'userId';
const TIMESTAMP = 'timestamp';
const SEPARATOR = '/';
/**
* Find data by the user id
*
* @param int $userId
*/
public function getDataByUserId($userId) {
$journal = new App\FileJournal(DATA_DIR . '/user/');
$driver = new App\FileStorage(DATA_DIR . '/user/', $journal);
$tag = self::USERID . self::SEPARATOR . $userId;
$nodes = $journal->findNodesByTag($tag);
foreach($nodes as $node) {
dump($driver->readByFilename($node[App\FileJournal::DATA][App\FileJournal::KEY]));
}
}
}