Author: develtainment
Date: 2010-03-12 15:29:03 +0100 (Fri, 12 Mar 2010)
New Revision: 28502
Added:
plugins/sfPropelCachePlugin/LICENSE
plugins/sfPropelCachePlugin/README
plugins/sfPropelCachePlugin/config/
plugins/sfPropelCachePlugin/config/databases.yml.sample
plugins/sfPropelCachePlugin/config/factories.yml.sample
plugins/sfPropelCachePlugin/data/
plugins/sfPropelCachePlugin/data/sql/
plugins/sfPropelCachePlugin/data/sql/sfPropelCache.MySQL.schema.sql
plugins/sfPropelCachePlugin/lib/
plugins/sfPropelCachePlugin/lib/sfPropelCache.class.php
Removed:
plugins/sfPropelCachePlugin/sfPropelCachePlugin-1.0.0/
Log:
init-fix
Added: plugins/sfPropelCachePlugin/LICENSE
===================================================================
--- plugins/sfPropelCachePlugin/LICENSE (rev 0)
+++ plugins/sfPropelCachePlugin/LICENSE 2010-03-12 14:29:03 UTC (rev 28502)
@@ -0,0 +1,7 @@
+Copyright (c) 2010 Tobias Sülzenbrück
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
Added: plugins/sfPropelCachePlugin/README
===================================================================
--- plugins/sfPropelCachePlugin/README (rev 0)
+++ plugins/sfPropelCachePlugin/README 2010-03-12 14:29:03 UTC (rev 28502)
@@ -0,0 +1,34 @@
+sfPropelCache Plugin
+====================
+
+Installation
+------------
+
+ * Install the plugin
+
+ $ symfony plugin:install sfPropelCachePlugin
+
+ * Setup sfPropelCache as view cache in your `factories.yml` (see
`config/factories.yml.sample`):
+
+ [yml]
+ all:
+ view_cache:
+ class: sfPropelCache
+ param:
+ automatic_cleaning_factor: 10
+
+ * Add the database connection parameters to your `databases.yml` (see
`config/databases.yml.sample`):
+
+ [yml]
+ cache_db_connection:
+ dsn: mysql:dbname=your_dbname;host=localhost
+ username: your_username
+ password: your_password
+
+ all:
+ ...
+
+ * Add the cache table (`dt_cache`) to the indicated database. For MySQL you
may use the provided sql file (see `data/sql/sfPropelCache.MySQL.schema.sql`).
+
+
+
\ No newline at end of file
Added: plugins/sfPropelCachePlugin/config/databases.yml.sample
===================================================================
--- plugins/sfPropelCachePlugin/config/databases.yml.sample
(rev 0)
+++ plugins/sfPropelCachePlugin/config/databases.yml.sample 2010-03-12
14:29:03 UTC (rev 28502)
@@ -0,0 +1,4 @@
+cache_db_connection:
+ dsn: mysql:dbname=your_dbname;host=localhost
+ username: your_username
+ password: your_password
Added: plugins/sfPropelCachePlugin/config/factories.yml.sample
===================================================================
--- plugins/sfPropelCachePlugin/config/factories.yml.sample
(rev 0)
+++ plugins/sfPropelCachePlugin/config/factories.yml.sample 2010-03-12
14:29:03 UTC (rev 28502)
@@ -0,0 +1,5 @@
+all:
+ view_cache:
+ class: sfMySQLCache
+ param:
+ automatic_cleaning_factor: 10
\ No newline at end of file
Added: plugins/sfPropelCachePlugin/data/sql/sfPropelCache.MySQL.schema.sql
===================================================================
--- plugins/sfPropelCachePlugin/data/sql/sfPropelCache.MySQL.schema.sql
(rev 0)
+++ plugins/sfPropelCachePlugin/data/sql/sfPropelCache.MySQL.schema.sql
2010-03-12 14:29:03 UTC (rev 28502)
@@ -0,0 +1,25 @@
+# ###############################################
+# Table definition for sfPropelCachePlugin
+# by Tobias Sülzenbrück <[email protected]
+# ###############################################
+
+SET FOREIGN_KEY_CHECKS = 0;
+
+#-------------------------------------------------
+#-- dt_cache
+#-------------------------------------------------
+
+DROP TABLE IF EXISTS `dt_cache`;
+
+CREATE TABLE `dt_cache`
+(
+ `key` varchar(255) NOT NULL,
+ `data` longtext NOT NULL,
+ `timeout` int(11) NOT NULL DEFAULT '0',
+ `last_modified` int(11) NOT NULL DEFAULT '0',
+ UNIQUE KEY `cache_unique_key` (`key`),
+ KEY `idx_timeout` (`timeout`),
+ KEY `idx_last_modified` (`last_modified`)
+)ENGINE=InnoDB;
+
+SET FOREIGN_KEY_CHECKS = 1;
Added: plugins/sfPropelCachePlugin/lib/sfPropelCache.class.php
===================================================================
--- plugins/sfPropelCachePlugin/lib/sfPropelCache.class.php
(rev 0)
+++ plugins/sfPropelCachePlugin/lib/sfPropelCache.class.php 2010-03-12
14:29:03 UTC (rev 28502)
@@ -0,0 +1,219 @@
+<?php
+/**
+ * sfPropelCache.
+ *
+ * @package develtainment
+ * @subpackage sfPropelCache
+ * @author Tobias Sülzenbrück <[email protected]>
+ * @author Klaus Großmann <[email protected]>
+ * @version SVN: $Id: sfPropelCache.class.php 213 2010-03-11 23:24:16Z
klaus $
+ */
+
+class sfPropelCache extends sfCache
+{
+ protected $con = null;
+ protected $config_name = 'cache_db_connection';
+ protected $table_name = 'dt_cache';
+ protected $col_key = 'key';
+ protected $col_data = 'data';
+ protected $col_timeout = 'timeout';
+ protected $col_last_modified = 'last_modified';
+
+ /**
+ * Initializes this sfCache instance.
+ *
+ * Available options:
+ *
+ * * database: File where to put the cache database (or :memory: to store
cache in memory)
+ *
+ * * see sfCache for options available for all drivers
+ *
+ * @see sfCache
+ */
+ public function initialize($options = array())
+ {
+ // disable auto_start
+ $options['auto_start'] = false;
+
+ // initialize the parent
+ parent::initialize($options);
+
+ $config = sfYaml::load(sfConfig::get('sf_config_dir').'/databases.yml');
+
+ if (!isset($config[$this->config_name]))
+ {
+ throw new sfInitializationException('You must provide a
"'.$this->config_name.'" information in databases.yml to sfPropelCache.');
+ }
+
+ $cache_db_connection = $config[$this->config_name];
+
+ if (!isset($cache_db_connection['dsn']))
+ {
+ throw new sfInitializationException('You must provide a "dsn" option to
sfPropelCache.');
+ }
+
+ if (!isset($cache_db_connection['username']))
+ {
+ throw new sfInitializationException('You must provide a "username"
option to sfPropelCache.');
+ }
+
+ if (!isset($cache_db_connection['password']))
+ {
+ throw new sfInitializationException('You must provide a "password"
option to sfPropelCache.');
+ }
+
+ $this->con = new PDO( $cache_db_connection['dsn'],
$cache_db_connection['username'], $cache_db_connection['password']);
+ }
+
+ /**
+ * @see sfCache
+ */
+ public function getHash($key)
+ {
+ return $key;
+ }
+
+ /**
+ * @see sfCache
+ */
+ public function getBackend()
+ {
+ return $this->con;
+ }
+
+ /**
+ * @see sfCache
+ */
+ public function get($key, $default = null)
+ {
+ $stmt = $this->con->prepare('SELECT `'.$this->col_data.'` FROM
`'.$this->table_name.'` WHERE `'.$this->col_key.'` = :key LIMIT 0, 1 ');
+ $stmt->bindValue(':key', self::getHash($key), PDO::PARAM_STR);
+ $stmt->execute();
+
+ $resultset = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ $data = $resultset[$this->col_data];
+ return null === $data ? $default : $data;
+ }
+
+ /**
+ * @see sfCache
+ */
+ public function has($key)
+ {
+ $stmt = $this->con->prepare('SELECT `'.$this->col_key.'` FROM
`'.$this->table_name.'` WHERE `'.$this->col_key.'` = :key LIMIT 0, 1 ');
+ $stmt->bindValue(':key', self::getHash($key), PDO::PARAM_STR);
+ $stmt->execute();
+
+ $resultset = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ if ($resultset) {
+ return true;
+ }else {
+ return false;
+ }
+ }
+
+ /**
+ * @see sfCache
+ */
+ public function set($key, $data, $lifetime = null)
+ {
+ if ($this->getOption('automatic_cleaning_factor') > 0 && rand(1,
$this->getOption('automatic_cleaning_factor')) == 1)
+ {
+ $this->clean(sfCache::OLD);
+ }
+
+ $stmt = $this->con->prepare('INSERT INTO `'.$this->table_name.'`
(`'.$this->col_key.'`, `'.$this->col_data.'`, `'.$this->col_timeout.'`,
`'.$this->col_last_modified.'`) VALUES (:key, :data, :timeout, :last_modified)
ON DUPLICATE KEY UPDATE `'.$this->col_key.'` = :key, `'.$this->col_data.'` =
:data, `'.$this->col_timeout.'` = :timeout, `'.$this->col_last_modified.'` =
:last_modified ');
+ $stmt->bindValue(':key', self::getHash($key), PDO::PARAM_STR);
+ $stmt->bindValue(':data', $data, PDO::PARAM_STR);
+ $stmt->bindValue(':timeout', (time() + $this->getLifetime($lifetime)),
PDO::PARAM_INT);
+ $stmt->bindValue(':last_modified', time(), PDO::PARAM_INT);
+
+ return (boolean) $stmt->execute();
+ }
+
+ /**
+ * @see sfCache
+ */
+ public function remove($key)
+ {
+ $stmt = $this->con->prepare('DELETE FROM `'.$this->table_name.'` WHERE
`'.$this->col_key.'` = :key LIMIT 0, 1 ');
+ $stmt->bindValue(':key', self::getHash($key), PDO::PARAM_STR);
+
+ return (boolean) $stmt->execute();
+ }
+
+ /**
+ * @see sfCache
+ */
+ public function removePattern($pattern)
+ {
+ $stmt = $this->con->prepare('DELETE FROM `'.$this->table_name.'` WHERE
REGEXP(:pattern, `'.$this->col_key.'`)');
+ $stmt->bindValue(':pattern', self::patternToRegexp($pattern),
PDO::PARAM_STR);
+
+ return (boolean) $stmt->execute();
+ }
+
+ /**
+ * @see sfCache
+ */
+ public function clean($mode = sfCache::ALL)
+ {
+ if (sfCache::OLD == $mode) {
+ $stmt = $this->con->prepare('DELETE FROM `'.$this->table_name.'` WHERE
`'.$this->col_timeout.'` < :timeout ');
+ $stmt->bindValue(':timeout', time(), PDO::PARAM_INT);
+ }else {
+ $stmt = $this->con->prepare('TRUNCATE TABLE `'.$this->table_name.'` ');
+ }
+
+ return (boolean) $stmt->execute();
+ }
+
+ /**
+ * @see sfCache
+ */
+ public function getTimeout($key)
+ {
+ $stmt = $this->con->prepare('SELECT `'.$this->col_timeout.'` FROM
`'.$this->table_name.'` WHERE `'.$this->col_key.'` = :key AND
`'.$this->col_timeout.'` > :timeout LIMIT 0, 1 ');
+ $stmt->bindValue(':key', self::getHash($key), PDO::PARAM_STR);
+ $stmt->bindValue(':timeout', time(), PDO::PARAM_INT);
+ $stmt->execute();
+
+ $resultset = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ if ($resultset && isset($resultset[$this->col_timeout])) {
+ return intval($resultset[$this->col_timeout]);
+ }else {
+ return 0;
+ }
+ }
+
+ /**
+ * @see sfCache
+ */
+ public function getLastModified($key)
+ {
+ $stmt = $this->con->prepare('SELECT `'.$this->col_last_modified.'` FROM
`'.$this->table_name.'` WHERE `'.$this->col_key.'` = :key AND
`'.$this->col_timeout.'` > :timeout LIMIT 0, 1 ');
+ $stmt->bindValue(':key', self::getHash($key), PDO::PARAM_STR);
+ $stmt->bindValue(':timeout', time(), PDO::PARAM_INT);
+ $stmt->execute();
+
+ $resultset = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ if ($resultset && isset($resultset[$this->col_last_modified])) {
+ return intval($resultset[$this->col_last_modified]);
+ }else {
+ return 0;
+ }
+ }
+
+ /**
+ * Callback used when deleting keys from cache.
+ */
+ public function removePatternRegexpCallback($regexp, $key)
+ {
+ return preg_match($regexp, $key);
+ }
+
+}
\ No newline at end of file
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.