Add sqlite cache driver #202

Closed
wants to merge 3 commits into
from

Conversation

Projects
None yet
3 participants

Baachi commented Oct 8, 2012

No description provided.

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

beberlei Nov 15, 2012

Owner

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

@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

beberlei Nov 15, 2012

Owner

wrong for expired entries

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

beberlei Nov 15, 2012

Owner

this doesnt work correctly with namespaces.

@Baachi

Baachi Nov 15, 2012

What do you mean?

Baachi closed this May 23, 2013

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