__construct ( $name, $location, $expires, $gzip )

Constructs a new instance of this class.

Access

public

Parameters

Parameter

Type

Required

Description

$name

string

Required

A name to uniquely identify the cache object.

$location

string

Optional

The location to store the cache object in. This may vary by cache method. The default value is NULL.

$expires

integer

Optional

The number of seconds until a cache object is considered stale. The default value is 0.

$gzip

boolean

Optional

Whether data should be gzipped before being stored. The default value is true.

Returns

Type

Description

object

Reference to the cache object.

Source

Method defined in lib/cachecore/cachemc.class.php | Toggle source view (51 lines) | View on GitHub

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;
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback