Skip to content

Add sqlite cache driver #202

Closed
wants to merge 3 commits into from

3 participants

@Baachi
Baachi commented Oct 8, 2012

No description provided.

@doctrinebot

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DCOM-123

@beberlei beberlei commented on an outdated diff Nov 15, 2012
lib/Doctrine/Common/Cache/SQLiteCache.php
+ /**
+ * {@inheritDoc}
+ */
+ protected function doFlush()
+ {
+ return $this->db->exec('DELETE FROM doctrine_cache');
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected function doSave($id, $data, $lifeTime = false)
+ {
+ $data = serialize($data);
+
+ $stmt = $this->db->prepare('INSERT INTO doctrine_cache (cache_key, cache_data, cache_expired_at) VALUES(:id, :data, :lifetime)');
@beberlei
Doctrine member
beberlei added a note Nov 15, 2012

This doesnt work if the entry exists already, but is expired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@beberlei beberlei commented on an outdated diff Nov 15, 2012
lib/Doctrine/Common/Cache/SQLiteCache.php
+ {
+ if (':memory:' === $dsn) {
+ $this->db = new \SQLite3($dsn);
+ } else {
+ $this->db = new \SQLite3($dsn, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE);
+ }
+
+ $this->initDb();
+ }
+
+ /**
+ * {@inhertiDoc}
+ */
+ protected function doContains($id)
+ {
+ $stmt = $this->db->prepare('SELECT COUNT(*) FROM doctrine_cache WHERE cache_key = :id');
@beberlei
Doctrine member
beberlei added a note Nov 15, 2012

wrong for expired entries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Baachi
Baachi commented Nov 15, 2012

@beberlei Good catch. Should be fixed now.

@beberlei beberlei commented on the diff Nov 15, 2012
lib/Doctrine/Common/Cache/SQLiteCache.php
+ {
+ $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', time());
+
+ $data = $stmt->execute()->fetchArray(SQLITE3_NUM);
+
+ return unserialize($data[0]);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected function doFlush()
+ {
+ return $this->db->exec('DELETE FROM doctrine_cache');
@beberlei
Doctrine member
beberlei added a note Nov 15, 2012

this doesnt work correctly with namespaces.

@Baachi
Baachi added a note Nov 15, 2012

What do you mean?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Baachi Baachi closed this May 23, 2013
@Baachi Baachi deleted the Baachi:sqlite-cache branch May 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.