• Facebook
  • Twitter
  • Yahoo
  • Linkedin
  • Google
  • Live

1. Create a file at "PF.Base/include/library/phpfox/cache/memory.class.php" and its code is

class Phpfox_Cache_Memory {

    private $_dircache = PHPFOX_DIR_CACHE . "memory" . PHPFOX_DS;

    private function getFile($sName) {
        return $this->_dircache . $sName . ".php";
    }

    public function write($sName) {
        
        if (!is_dir($this->_dircache)) {
            @mkdir($this->_dircache, 0777, 1);
            @chmod($this->_dircache, 0777);
        }   
        
        $aName = explode("_", $sName);
        $oFile = Phpfox::getLib('file');

        if (strstr($sName, PHPFOX_DS) < 0)
            return;

        if (count($aName) > 1) {
            $key = $aName[0];
            $sFile = $this->getFile($key);

            if (!file_exists($sFile)) {
                $oFile->write($sFile, "");
            }

            $loadFile = file_get_contents($sFile);

            if (empty(trim($loadFile)))
                $aRows = array();
            else
                $aRows = explode(",", $loadFile);

            if (!is_array($aRows)) {
                $oFile->write($sFile, $sName);
                return;
            }

            if (in_array($sName, $aRows))
                return;

            array_push($aRows, $sName);
            $oFile->write($sFile, implode(",", $aRows));
        }
    }

    public function get($sFile) {
        if (file_exists($sFile)) {
            return explode(",", file_get_contents($sFile));
        }
        return null;
    }

    public function remove($sName = null, $sType = '', $driver) {
        $sFile = $this->getFile($sName);
        $aRows = $this->get($sFile);
        
        if ($sType == "substr" && is_array($aRows)) {
           
            foreach ($aRows as $aRow) {
                $driver->delete('__cache__' . $aRow);
            }        
            @unlink($sFile);
        }
    }
}


2. Add code at PF.Base/include/package.config.php

'cache.memory'             => \Phpfox_Cache_Memory::class, under this line 'cache.storage.driver'       => \Phpfox_Cache_Storage_Driver::class,

3. Add code at /PF.Base/include/class_map.config.php

'phpfox.cache.memory'                => 'library/phpfox/cache/memory.class.php',

4. Add some codes at /PF.Base/include/library/phpfox/cache/storage/driver.class.php

public function save($sId, $mContent) {

/* .... */

phpFox::getLib("cache.memory")->write($sId);
                
 return true;

}

public function remove($sName = null, $sType = ''){

/* ... */

phpFox::getLib("cache.memory")->remove($sName, $sType, $this->_driver);
        return true;

}

Congratulations! you already modified successfully.

Contact us here if you meet any problems.

1
  • October 24, 2017
  • 0 Comment(s)
Category: phpFox
Be the first person to like this