Author Topic: memcahe  (Read 17153 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
memcahe
« on: July 12, 2016, 11:38:05 PM »
I have been running memcache for years on all my sites.I have a server and have your service on a monitor system with your support.I have found out that cwp does not support memcahe.The issue I am having is how to possibly change my class_cache.php to make it work with another cach system or how to edit this to not use the cache?

this is the code
Code: [Select]
<?php

if (!extension_loaded('memcache')) {
    die(
'Memcache Extension not loaded.');
}

class 
CACHE extends Memcache {
    public 
$CacheHits = array();
    public 
$MemcacheDBArray = array();
    public 
$MemcacheDBKey '';
    protected 
$InTransaction false;
    public 
$Time 0;
    protected 
$Page = array();
    protected 
$Row 1;
    protected 
$Part 0;
    
    function 
__construct() {
        
$this->connect('127.0.0.1'11211);
    }
    
//---------- Caching functions ----------//
    // Wrapper for Memcache::set, with the zlib option removed and default duration of 1 hour
    
public function cache_value($Key$Value$Duration=2592000) {
        
$StartTime=microtime(true);
        if (empty(
$Key)) {
            
trigger_error("Cache insert failed for empty key");
        }
        if (!
$this->set($Key$Value0$Duration)) {
            
trigger_error("Cache insert failed for key $Key"E_USER_ERROR);
        }
        
$this->Time+=(microtime(true)-$StartTime)*1000;
    }
    public function 
add_value($Key$Value$Duration=2592000) {
        
$StartTime=microtime(true);
        if (empty(
$Key)) {
            
trigger_error("Cache insert failed for empty key");
        }
       
$add $this->add($Key$Value0$Duration);
       
$this->Time+=(microtime(true)-$StartTime)*1000;
       return 
$add;
    }
    public function 
get_value($Key$NoCache=false) {
        
$StartTime=microtime(true);
        if (empty(
$Key)) {
            
trigger_error("Cache retrieval failed for empty key");
        }
        
$Return $this->get($Key);
        
$this->Time+=(microtime(true)-$StartTime)*1000;
        return 
$Return;
    }
    public function 
replace_value($Key$Value$Duration=2592000) {
        
$StartTime=microtime(true);
        
$this->replace($Key$Valuefalse$Duration);
        
$this->Time+=(microtime(true)-$StartTime)*1000;
    }
    
// Wrapper for Memcache::delete. For a reason, see above.
    
public function delete_value($Key) {
        
$StartTime=microtime(true);
        if (empty(
$Key)) {
            
trigger_error("Cache retrieval failed for empty key");
        }
        if (!
$this->delete($Key,0)) {
        }
        
$this->Time+=(microtime(true)-$StartTime)*1000;
    }
    
//---------- memcachedb functions ----------//
    
public function begin_transaction($Key) {
        
$Value $this->get($Key);
        if (!
is_array($Value)) {
            
$this->InTransaction false;
            
$this->MemcacheDBKey = array();
            
$this->MemcacheDBKey '';
            return 
false;
        }
        
$this->MemcacheDBArray $Value;
        
$this->MemcacheDBKey $Key;
        
$this->InTransaction true;
        return 
true;
    }

    public function 
cancel_transaction() {
        
$this->InTransaction false;
        
$this->MemcacheDBKey = array();
        
$this->MemcacheDBKey '';
    }

    public function 
commit_transaction($Time=2592000) {
        if (!
$this->InTransaction) {
            return 
false;
        }
        
$this->cache_value($this->MemcacheDBKey$this->MemcacheDBArray$Time);
        
$this->InTransaction false;
    }
    
// Updates multiple rows in an array
    
public function update_transaction($Rows$Values) {
        if (!
$this->InTransaction) {
            return 
false;
        }
        
$Array $this->MemcacheDBArray;
        if (
is_array($Rows)) {
            
$i 0;
            
$Keys $Rows[0];
            
$Property $Rows[1];
            foreach (
$Keys as $Row) {
                
$Array[$Row][$Property] = $Values[$i];
                
$i++;
            }
        } else {
            
$Array[$Rows] = $Values;
        }
        
$this->MemcacheDBArray $Array;
    }
    
// Updates multiple values in a single row in an array
    // $Values must be an associative array with key:value pairs like in the array we're updating
    
public function update_row($Row$Values) {
        if (!
$this->InTransaction) {
            return 
false;
        }
        if (
$Row === false) {
            
$UpdateArray $this->MemcacheDBArray;
        } else {
            
$UpdateArray $this->MemcacheDBArray[$Row];
        }
        foreach (
$Values as $Key => $Value) {
            if (!
array_key_exists($Key$UpdateArray)) {
                
trigger_error('Bad transaction key ('.$Key.') for cache '.$this->MemcacheDBKey);
            }
            if (
$Value === '+1') {
                if (!
is_number($UpdateArray[$Key])) {
                    
trigger_error('Tried to increment non-number ('.$Key.') for cache '.$this->MemcacheDBKey);
                }
                ++
$UpdateArray[$Key]; // Increment value
            
} elseif ($Value === '-1') {
                if (!
is_number($UpdateArray[$Key])) {
                    
trigger_error('Tried to decrement non-number ('.$Key.') for cache '.$this->MemcacheDBKey);
                }
                --
$UpdateArray[$Key]; // Decrement value
            
} else {
                
$UpdateArray[$Key] = $Value// Otherwise, just alter value
            
}
        }
        if (
$Row === false) {
            
$this->MemcacheDBArray $UpdateArray;
        } else {
            
$this->MemcacheDBArray[$Row] = $UpdateArray;
        }
    }
}
//end class
?>


Any help would be appreciated

Offline
**
Re: memcahe
« Reply #1 on: November 07, 2019, 03:21:53 AM »
PROBLEM SOLVED

Hi, i discovered a great website https://www.mysterydata.com/ with a great administrator where you can find many guides for CWP and more, also by registering for free on the forum i found the solution to this problem thanks to the courtesy and extreme availability of the administrator.

SOLUTION:

https://forum.mysterydata.com/topic/4/cwp-help-to-install-memcached

Good day and good work to all !


« Stay hungry, stay foolish. »