本文整理汇总了PHP中CacheCore::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP CacheCore::__construct方法的具体用法?PHP CacheCore::__construct怎么用?PHP CacheCore::__construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CacheCore
的用法示例。
在下文中一共展示了CacheCore::__construct方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructs a new instance of this class.
*
* @param string $name (Required) A name to uniquely identify the cache object.
* @param string $location (Optional) The location to store the cache object in. This may vary by cache method. The default value is NULL.
* @param integer $expires (Optional) The number of seconds until a cache object is considered stale. The default value is 0.
* @param boolean $gzip (Optional) Whether data should be gzipped before being stored. The default value is true.
* @return object Reference to the cache object.
*/
public function __construct($name, $location = null, $expires = 0, $gzip = true)
{
parent::__construct($name, null, $expires, $gzip);
$this->id = $this->name;
// Prefer Memcached over Memcache.
if (class_exists('Memcached')) {
$this->memcache = new Memcached();
$this->is_memcached = true;
} elseif (class_exists('Memcache')) {
$this->memcache = new Memcache();
} else {
return false;
}
// Enable compression, if available
if ($this->gzip) {
if ($this->is_memcached) {
$this->memcache->setOption(Memcached::OPT_COMPRESSION, true);
} else {
$this->gzip = MEMCACHE_COMPRESSED;
}
}
// Process Memcached servers.
if (isset($location) && sizeof($location) > 0) {
foreach ($location as $loc) {
if (isset($loc['port']) && !empty($loc['port'])) {
$this->memcache->addServer($loc['host'], $loc['port']);
} else {
$this->memcache->addServer($loc['host'], 11211);
}
}
}
return $this;
}
示例2: __construct
/**
* Method: __construct()
* The constructor
*
* Access:
* public
*
* Parameters:
* name - _string_ (Required) A name to uniquely identify the cache object.
* location - _string_ (Required) The location to store the cache object in. This may vary by cache method.
* expires - _integer_ (Required) The number of seconds until a cache object is considered stale.
*
* Returns:
* _object_ Reference to the cache object.
*
* See Also:
* Example Usage - http://tarzan-aws.com/docs/examples/cachecore/cache.phps
*/
public function __construct($name, $location, $expires)
{
parent::__construct($name, null, $expires);
$this->id = $this->name;
$this->memcache = new Memcache();
if (extension_loaded('zlib')) {
$this->compressed = MEMCACHE_COMPRESSED;
}
foreach ($location as $loc) {
$this->memcache->addServer($loc['host'], $loc['port']);
}
}
示例3: __construct
/**
* Method: __construct()
* The constructor
*
* Access:
* public
*
* Parameters:
* name - _string_ (Required) A name to uniquely identify the cache object.
* location - _string_ (Required) The location to store the cache object in. This may vary by cache method.
* expires - _integer_ (Required) The number of seconds until a cache object is considered stale.
* gzip - _boolean_ (Optional) Whether data should be gzipped before being stored. Defaults to true.
*
* Returns:
* _object_ Reference to the cache object.
*/
public function __construct($name, $location, $expires, $gzip = true)
{
parent::__construct($name, null, $expires, $gzip);
$this->id = $this->name;
$this->memcache = new Memcache();
if ($this->gzip) {
$this->gzip = MEMCACHE_COMPRESSED;
}
if (isset($location) && sizeof($location) > 0) {
foreach ($location as $loc) {
if (isset($loc['port']) && !empty($loc['port'])) {
$this->memcache->addServer($loc['host'], $loc['port']);
} else {
$this->memcache->addServer($loc['host']);
}
}
}
return;
}
示例4: __construct
/**
* Constructs a new instance of this class.
*
* Tested with [MySQL 5.0.x](http://mysql.com), [PostgreSQL](http://postgresql.com), and
* [SQLite 3.x](http://sqlite.org). SQLite 2.x is assumed to work. No other PDO-supported databases have
* been tested (e.g. Oracle, Microsoft SQL Server, IBM DB2, ODBC, Sybase, Firebird). Feel free to send
* patches for additional database support.
*
* See <http://php.net/pdo> for more information.
*
* @param string $name (Required) A name to uniquely identify the cache object.
* @param string $location (Optional) The location to store the cache object in. This may vary by cache method. The default value is NULL.
* @param integer $expires (Optional) The number of seconds until a cache object is considered stale. The default value is 0.
* @param boolean $gzip (Optional) Whether data should be gzipped before being stored. The default value is true.
* @return object Reference to the cache object.
*/
public function __construct($name, $location = null, $expires = 0, $gzip = true)
{
// Make sure the name is no longer than 40 characters.
$name = sha1($name);
// Call parent constructor and set id.
parent::__construct($name, $location, $expires, $gzip);
$this->id = $this->name;
$options = array();
// Check if the location contains :// (e.g. mysql://user:pass@hostname:port/table)
if (stripos($location, '://') === false) {
// No? Just pass it through.
$this->dsn = parse_url($location);
$this->dsn_string = $location;
} else {
// Yes? Parse and set the DSN
$this->dsn = parse_url($location);
$this->dsn_string = $this->dsn['scheme'] . ':host=' . $this->dsn['host'] . (isset($this->dsn['port']) ? ';port=' . $this->dsn['port'] : '') . ';dbname=' . substr($this->dsn['path'], 1);
}
// Make sure that user/pass are defined.
$user = isset($this->dsn['user']) ? $this->dsn['user'] : null;
$pass = isset($this->dsn['pass']) ? $this->dsn['pass'] : null;
// Set persistence for databases that support it.
switch ($this->dsn['scheme']) {
case 'mysql':
// MySQL
// MySQL
case 'pgsql':
// PostgreSQL
$options[PDO::ATTR_PERSISTENT] = true;
break;
}
// Instantiate a new PDO object with a persistent connection.
$this->pdo = new PDO($this->dsn_string, $user, $pass, $options);
// Define prepared statements for improved performance.
$this->create = $this->pdo->prepare("INSERT INTO cache (id, expires, data) VALUES (:id, :expires, :data)");
$this->read = $this->pdo->prepare("SELECT id, expires, data FROM cache WHERE id = :id");
$this->reset = $this->pdo->prepare("UPDATE cache SET expires = :expires WHERE id = :id");
$this->delete = $this->pdo->prepare("DELETE FROM cache WHERE id = :id");
}
示例5: __construct
/**
* Method: __construct()
* The constructor
*
* Access:
* public
*
* Parameters:
* name - _string_ (Required) A name to uniquely identify the cache object.
* location - _string_ (Required) The location to store the cache object in. This may vary by cache method.
* expires - _integer_ (Required) The number of seconds until a cache object is considered stale.
* gzip - _boolean_ (Optional) Whether data should be gzipped before being stored. Defaults to true.
*
* Returns:
* _object_ Reference to the cache object.
*/
public function __construct($name, $location, $expires, $gzip = true)
{
parent::__construct($name, null, $expires, $gzip);
$this->id = $this->name;
}
示例6: __construct
/**
* Constructs a new instance of this class.
*
* @param string $name (Required) A name to uniquely identify the cache object.
* @param string $location (Optional) The location to store the cache object in. This may vary by cache method. The default value is NULL.
* @param integer $expires (Optional) The number of seconds until a cache object is considered stale. The default value is 0.
* @param boolean $gzip (Optional) Whether data should be gzipped before being stored. The default value is true.
* @return object Reference to the cache object.
*/
public function __construct($name, $location = null, $expires = 0, $gzip = true)
{
parent::__construct($name, $location, $expires, $gzip);
$this->id = $this->location . '/' . $this->name . '.cache';
}
示例7: __construct
/**
* Method: __construct()
* The constructor
*
* Access:
* public
*
* Parameters:
* name - _string_ (Required) A name to uniquely identify the cache object.
* location - _string_ (Required) The location to store the cache object in. This may vary by cache method.
* expires - _integer_ (Required) The number of seconds until a cache object is considered stale.
*
* Returns:
* _object_ Reference to the cache object.
*
* See Also:
* Example Usage - http://tarzan-aws.com/docs/examples/cachecore/cache.phps
*/
public function __construct($name, $location, $expires)
{
parent::__construct($name, $location, $expires);
$this->id = $this->location . '/' . $this->name . '.cache';
}