Init Repo

This commit is contained in:
root
2019-09-06 23:53:10 +08:00
commit f0ef89dfbb
7905 changed files with 914138 additions and 0 deletions

View File

@ -0,0 +1,9 @@
<?php
interface LtCacheAdapter
{
public function connect($hostConf);
public function add($key, $value, $ttl = 0, $tableName, $connectionResource);
public function del($key, $tableName, $connectionResource);
public function get($key, $tableName, $connectionResource);
public function update($key, $value, $ttl = 0, $tableName, $connectionResource);
}

View File

@ -0,0 +1,40 @@
<?php
class LtCacheAdapterApc implements LtCacheAdapter
{
public function connect($hostConf)
{
return true;
}
public function add($key, $value, $ttl = 0, $tableName, $connectionResource)
{
return apc_add($this->getRealKey($tableName, $key), $value, $ttl);
}
public function del($key, $tableName, $connectionResource)
{
return apc_delete($this->getRealKey($tableName, $key));
}
public function get($key, $tableName, $connectionResource)
{
return apc_fetch($this->getRealKey($tableName, $key));
}
public function update($key, $value, $ttl = 0, $tableName, $connectionResource)
{
if ($this->del($key, $tableName, $connectionResource))
{
return $this->add($key, $value, $ttl, $tableName, $connectionResource);
}
else
{
return false;
}
}
protected function getRealKey($tableName, $key)
{
return $tableName . "-" . $key;
}
}

View File

@ -0,0 +1,49 @@
<?php
class LtCacheAdapterEAccelerator implements LtCacheAdapter
{
public function connect($hostConf)
{
return true;
}
public function add($key, $value, $ttl=0, $tableName, $connectionResource)
{
$value = serialize($value); //eAccelerator doesn't serialize object
return eaccelerator_put($this->getRealKey($tableName, $key), $value, $ttl);
}
public function del($key, $tableName, $connectionResource)
{
return eaccelerator_rm($this->getRealKey($tableName, $key));
}
public function get($key, $tableName, $connectionResource)
{
$value = eaccelerator_get($this->getRealKey($tableName, $key));
if (!empty($value))
{
return unserialize($value);
}
else
{
return false;
}
}
public function update($key, $value, $ttl = 0, $tableName, $connectionResource)
{
if ($this->del($key, $tableName, $connectionResource))
{
return $this->add($key, $value, $ttl, $tableName, $connectionResource);
}
else
{
return false;
}
}
protected function getRealKey($tableName, $key)
{
return $tableName . "-" . $key;
}
}

View File

@ -0,0 +1,68 @@
<?php
class LtCacheAdapterFile implements LtCacheAdapter
{
public function connect($hostConf)
{
$fileStore = new LtStoreFile;
$fileStore->prefix = 'LtCache-file';
$fileStore->useSerialize = true;
$fileStore->init();
return $fileStore;
}
public function add($key, $value, $ttl = 0, $tableName, $connectionResource)
{
if (0 != $ttl)
{
$ttl += time();
}
if (true == $connectionResource->add($this->getRealKey($tableName, $key), array("ttl" => $ttl, "value" => $value)))
{
return true;
}
else
{
if ($this->get($key,$tableName,$connectionResource))
{
return false;
}
else
{
$this->del($key,$tableName,$connectionResource);
return $connectionResource->add($this->getRealKey($tableName, $key), array("ttl" => $ttl, "value" => $value));
}
}
}
public function del($key, $tableName, $connectionResource)
{
return $connectionResource->del($this->getRealKey($tableName, $key));
}
public function get($key, $tableName, $connectionResource)
{
$cachedArray = $connectionResource->get($this->getRealKey($tableName, $key));
if (is_array($cachedArray) && (0 == $cachedArray["ttl"] || $cachedArray["ttl"] > time()))
{
return $cachedArray["value"];
}
else
{
return false;
}
}
public function update($key, $value, $ttl = 0, $tableName, $connectionResource)
{
if (0 != $ttl)
{
$ttl += time();
}
return $connectionResource->update($this->getRealKey($tableName, $key), array("ttl" => $ttl, "value" => $value));
}
protected function getRealKey($tableName, $key)
{
return $tableName . "-" . $key;
}
}

View File

@ -0,0 +1,33 @@
<?php
class LtCacheAdapterMemcache implements LtCacheAdapter
{
public function connect($hostConf)
{
return memcache_connect($hostConf["host"], $hostConf["port"]);
}
public function add($key, $value, $ttl = 0, $tableName, $connectionResource)
{
return $connectionResource->add($this->getRealKey($tableName, $key), $value, false, $ttl);
}
public function del($key, $tableName, $connectionResource)
{
return $connectionResource->delete($this->getRealKey($tableName, $key), 0);
}
public function get($key, $tableName, $connectionResource)
{
return $connectionResource->get($this->getRealKey($tableName, $key));
}
public function update($key, $value, $ttl = 0, $tableName, $connectionResource)
{
return $connectionResource->replace($this->getRealKey($tableName, $key), $value, false, $ttl);
}
protected function getRealKey($tableName, $key)
{
return $tableName . "-" . $key;
}
}

View File

@ -0,0 +1,35 @@
<?php
class LtCacheAdapterMemcached implements LtCacheAdapter
{
public function connect($hostConf)
{
$connectionResource = new Memcached();
$connectionResource->addServer($hostConf["host"], $hostConf["port"]);
return $connectionResource;
}
public function add($key, $value, $ttl=0, $tableName, $connectionResource)
{
return $connectionResource->add($this->getRealKey($tableName, $key), $value, $ttl);
}
public function del($key, $tableName, $connectionResource)
{
return $connectionResource->delete($this->getRealKey($tableName, $key));
}
public function get($key, $tableName, $connectionResource)
{
return $connectionResource->get($this->getRealKey($tableName, $key));
}
public function update($key, $value, $ttl = 0, $tableName, $connectionResource)
{
return $connectionResource->replace($this->getRealKey($tableName, $key), $value, $ttl);
}
protected function getRealKey($tableName, $key)
{
return $tableName . "-" . $key;
}
}

View File

@ -0,0 +1,55 @@
<?php
class LtCacheAdapterPhps implements LtCacheAdapter
{
public function connect($hostConf)
{
$fileStore = new LtStoreFile;
if (isset($hostConf['host']) && is_string($hostConf['host']))
{
$fileStore->cacheFileRoot = $hostConf['host'];
$fileStore->prefix = 'Ltcache-phps-';
$fileStore->init();
return $fileStore;
}
else
{
trigger_error("Must set [host]");
return false;
}
}
public function add($key, $value, $ttl = 0, $tableName, $connectionResource)
{
return $connectionResource->add($this->getRealKey($tableName, $key), $this->valueToString($value), $ttl);
}
public function del($key, $tableName, $connectionResource)
{
return $connectionResource->del($this->getRealKey($tableName, $key));
}
public function get($key, $tableName, $connectionResource)
{
return $this->stringToValue($connectionResource->get($this->getRealKey($tableName, $key)));
}
public function update($key, $value, $ttl = 0, $tableName, $connectionResource)
{
return $connectionResource->update($this->getRealKey($tableName, $key), $this->valueToString($value), $ttl);
}
protected function getRealKey($tableName, $key)
{
return $tableName . "-" . $key;
}
protected function valueToString($value)
{
return serialize($value);
}
protected function stringToValue($str)
{
return unserialize($str);
}
}

View File

@ -0,0 +1,43 @@
<?php
class LtCacheAdapterXcache implements LtCacheAdapter
{
public function connect($hostConf)
{
return true;
}
public function add($key, $value, $ttl = 0, $tableName, $connectionResource)
{
return xcache_set($this->getRealKey($tableName, $key), $value, $ttl);
}
public function del($key, $tableName, $connectionResource)
{
return xcache_unset($this->getRealKey($tableName, $key));
}
public function get($key, $tableName, $connectionResource)
{
$key = $this->getRealKey($tableName, $key);
if (xcache_isset($key))
{
return xcache_get($key);
}
return false;
}
public function update($key, $value, $ttl = 0, $tableName, $connectionResource)
{
$key = $this->getRealKey($tableName, $key);
if (xcache_isset($key))
{
return xcache_set($key, $value, $ttl);
}
return false;
}
protected function getRealKey($tableName, $key)
{
return $tableName . "-" . $key;
}
}