/**
  * 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;
 }
Example #2
0
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         $caching_system = _PS_CACHING_SYSTEM_;
         self::$_instance = new $caching_system();
     }
     return self::$_instance;
 }
 /**
  * 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']);
     }
 }
Example #4
0
 public static function chobits_getcachevars($data, $type = 'VAR')
 {
     $evaluate = '';
     foreach ($data as $key => $val) {
         if (is_array($val)) {
             $evaluate .= "\${$key} = " . CacheCore::chobits_arrayeval($val) . ";\n";
         } else {
             $val = addcslashes($val, '\'\\');
             $evaluate .= $type == 'VAR' ? "\${$key} = '{$val}';\n" : "define('" . strtoupper($key) . "', '{$val}');\n";
         }
     }
     return $evaluate;
 }
Example #5
0
 /**
  * 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;
 }
 /**
  * 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");
 }
 /**
  * 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;
 }
 /**
  * Fetches and caches EC2 instance profile credentials. This is meant to be used by the constructor, and is not to
  * be manually invoked.
  *
  * @param CacheCore $cache (Required) The a reference to the cache object that is being used to handle the caching.
  * @param array $options (Required) The options that were passed into the constructor.
  * @return mixed The data to be cached, or NULL.
  */
 public function cache_instance_profile_credentials($cache, $options)
 {
     $instance_profile_url = 'http://169.254.169.254/latest/meta-data/iam/security-credentials/';
     $connect_timeout = isset($options['instance_profile_timeout']) ? $options['instance_profile_timeout'] : 2;
     try {
         // Make a call to the EC2 Metadata Service to find the available instance profile
         $request = new RequestCore($instance_profile_url);
         $request->set_curlopts(array(CURLOPT_CONNECTTIMEOUT => $connect_timeout));
         $response = $request->send_request(true);
         if ($response->isOK()) {
             // Get the instance profile name
             $profile = (string) $response->body;
             // Make a call to the EC2 Metadata Service to get the instance profile credentials
             $request = new RequestCore($instance_profile_url . $profile);
             $request->set_curlopts(array(CURLOPT_CONNECTTIMEOUT => $connect_timeout));
             $response = $request->send_request(true);
             if ($response->isOK()) {
                 // Get the credentials
                 $credentials = json_decode($response->body, true);
                 if ($credentials['Code'] === 'Success') {
                     // Determine the expiration time
                     $expiration_time = strtotime((string) $credentials['Expiration']);
                     $expiration_duration = round(($expiration_time - time()) * 0.85);
                     $cache->expire_in($expiration_duration);
                     // Return the credential information
                     return array('key' => $credentials['AccessKeyId'], 'secret' => $credentials['SecretAccessKey'], 'token' => $credentials['Token'], 'expires' => $credentials['Expiration']);
                 }
             }
         }
     } catch (cURL_Exception $e) {
         // The EC2 Metadata Service does not exist or had timed out.
         // An exception will be thrown on the next line.
     }
     // @codeCoverageIgnoreStart
     throw new CFCredentials_Exception('No credentials were provided. The SDK attempted to retrieve Instance ' . 'Profile credentials from the EC2 Instance Metadata Service, but failed to do so. Instance profile ' . 'credentials are only accessible on EC2 instances configured with a specific IAM role.');
     // @codeCoverageIgnoreEnd
 }
Example #9
0
 /**
  * Unit testing purpose only
  */
 public static function deleteTestingInstance()
 {
     self::$instance = null;
 }
Example #10
0
 /**
  * Fetches and caches STS credentials. This is meant to be used by the constructor, and is not to be
  * manually invoked.
  *
  * @param CacheCore $cache (Required) The a reference to the cache object that is being used to handle the caching.
  * @param array $options (Required) The options that were passed into the constructor.
  * @return mixed The data to be cached, or NULL.
  */
 public function cache_sts_credentials($cache, $options)
 {
     $token = new AmazonSTS($options);
     $response = $token->get_session_token();
     if ($response->isOK()) {
         // Update the expiration
         $expiration_time = strtotime((string) $response->body->GetSessionTokenResult->Credentials->Expiration);
         $expiration_duration = round(($expiration_time - time()) * 0.85);
         $cache->expire_in($expiration_duration);
         // Return the important data
         return array('key' => (string) $response->body->GetSessionTokenResult->Credentials->AccessKeyId, 'secret' => (string) $response->body->GetSessionTokenResult->Credentials->SecretAccessKey, 'token' => (string) $response->body->GetSessionTokenResult->Credentials->SessionToken, 'expires' => (string) $response->body->GetSessionTokenResult->Credentials->Expiration);
     }
     return null;
 }
 /**
  * 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';
 }
 /**
  * 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';
 }
Example #13
0
 public static function UpdateSettingsCache()
 {
     global $db, $nw_uid, $tablepre, $timestamp, $adminid, $basic_settings, $webservice_settings;
     $cur_settings = self::FetchSettings();
     foreach ($cur_settings as $key => $value) {
         $data['nowhere_settings'][$key] = $value;
     }
     CacheCore::chobits_writetocache('nowhere_settings', '', CacheCore::chobits_getcachevars($data), '', 'cache');
 }