Back to FileStorage class

Method store

public bool
store
(mixed $id, mixed $group, mixed $data)
Store the data to cache by ID and group
Parameters
  • string $id The cache data ID
  • string $group The cache data group
  • string $data The data to store in cache
Returns
  • bool
Since
  • 1.7.0
Class: FileStorage
Project: Joomla

Method store - Source code

/**
 * Store the data to cache by ID and group
 *
 * @param   string  $id     The cache data ID
 * @param   string  $group  The cache data group
 * @param   string  $data   The data to store in cache
 *
 * @return  boolean
 *
 * @since   1.7.0
 */
public function store($id, $group, $data)
{
    $path = $this->_getFilePath($id, $group);
    $close = false;
    // Prepend a die string
    $data = '<?php die("Access Denied"); ?>#x#' . $data;
    if (isset($this->_locked_files[$path])) {
        $_fileopen = $this->_locked_files[$path];
        // Because lock method uses flag c+b we have to truncate it manually
        @ftruncate($_fileopen, 0);
    } else {
        $_fileopen = @fopen($path, 'wb');
        // There is no lock, we have to close file after store data
        $close = true;
    }
    if ($_fileopen) {
        $length = \strlen($data);
        $result = @fwrite($_fileopen, $data, $length);
        if ($close) {
            @fclose($_fileopen);
        }
        return $result === $length;
    }
    return false;
}