Skip to content

Commit

Permalink
Update to pathological case in SqliteCacheProvider when two concurren…
Browse files Browse the repository at this point in the history
…t requests attempt to create tables at nearly the same time. One request will fail and we should now recover fine.
  • Loading branch information
KrisJordan committed May 4, 2009
1 parent cb565a3 commit 2291880
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions recess/recess/cache/Cache.class.php
Expand Up @@ -237,6 +237,7 @@ function __construct() {
$tries = 0;
while($tries < 2) {
try {
$tries++;
$this->setStatement = $this->pdo->prepare('INSERT OR REPLACE INTO cache (key,value,expire) values (:key,:value,:expire)');
$this->getStatement = $this->pdo->prepare('SELECT value,expire FROM cache WHERE key = :key');
$this->getManyStatement = $this->pdo->prepare('SELECT value,expire,key FROM cache WHERE key LIKE :key');
Expand All @@ -247,11 +248,10 @@ function __construct() {
$this->pdo->exec('CREATE TABLE "cache" ("key" TEXT PRIMARY KEY NOT NULL , "value" TEXT NOT NULL , "expire" INTEGER NOT NULL)');
$this->pdo->exec('CREATE INDEX "expiration" ON "cache" ("expire" ASC)');
} catch(PDOException $e) {
if($tries == 1) {
die('Could not create cache table');
if($tries == 2) {
die('Could not create cache table.');
}
sleep(1);
$tries++;
continue;
}
}
Expand Down

0 comments on commit 2291880

Please sign in to comment.