Permalink
Browse files

Rename files and small fixes

  • Loading branch information...
1 parent 885f9aa commit a736edf92db3cf470f95b99e4b7f6fe0198e75d7 @Baachi committed Oct 8, 2012
@@ -28,7 +28,7 @@
* @since 2.4
* @author Markus Bachmann <markus.bachmann@bachi.biz>
*/
-class SQLite extends CacheProvider
+class SQLiteCache extends CacheProvider
{
/**
* @var \SQLite3
@@ -42,7 +42,11 @@ class SQLite extends CacheProvider
*/
public function __construct($dsn)
{
- $this->db = new \SQLite3($dsn, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE);
+ if (':memory:' === $dsn) {
+ $this->db = new \SQLite3($dsn);
+ } else {
+ $this->db = new \SQLite3($dsn, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE);
+ }
$this->initDb();
}
@@ -78,10 +82,11 @@ protected function doFetch($id)
{
$stmt = $this->db->prepare('SELECT cache_data FROM doctrine_cache WHERE cache_key = :id AND (cache_expired_at = 0 OR cache_expired_at >= :date)');
$stmt->bindParam('id', $id);
- $stmt->bindValue('date', date(DATE_ISO8601));
+ $stmt->bindValue('date', time());
$data = $stmt->execute()->fetchArray(SQLITE3_NUM);
- return unserialize(base64_decode($data[0]));
+
+ return unserialize($data[0]);
}
/**
@@ -97,12 +102,12 @@ protected function doFlush()
*/
protected function doSave($id, $data, $lifeTime = false)
{
- $data = base64_encode(serialize($data));
+ $data = serialize($data);
$stmt = $this->db->prepare('INSERT INTO doctrine_cache (cache_key, cache_data, cache_expired_at) VALUES(:id, :data, :lifetime)');
- $stmt->bindParam('id', $id, SQLITE3_TEXT);
- $stmt->bindParam('data', $data, SQLITE3_BLOB);
- $stmt->bindParam('lifetime', $lifeTime, SQLITE3_INTEGER);
+ $stmt->bindParam('id', $id);
+ $stmt->bindParam('data', $data);
+ $stmt->bindParam('lifetime', $lifeTime);
return $stmt->execute();
}
@@ -2,22 +2,10 @@
namespace Doctrine\Tests\Common\Cache;
-use Doctrine\Common\Cache\SQLite;
+use Doctrine\Common\Cache\SQLiteCache;
-class SQLiteTest extends CacheTest
+class SQLiteCacheTest extends CacheTest
{
- public static $path;
-
- public static function setUpBeforeClass()
- {
- static::$path = sys_get_temp_dir().'/doctrine-common.db';
- }
-
- public static function tearDownAfterClass()
- {
- @unlink(static::$path);
- }
-
public function testGetStats()
{
$cache = $this->_getCacheDriver();
@@ -37,6 +25,6 @@ protected function setup()
*/
protected function _getCacheDriver()
{
- return new SQLite(static::$path);
+ return new SQLiteCache(':memory');
}
}

0 comments on commit a736edf

Please sign in to comment.