KD2 Framework  Check-in [9f6ac43d67]

Overview
Comment:Memory cache
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9f6ac43d6794a86a2b0df3ae7e83bd5046a126f8
User & Date: bohwaz on 2016-06-21 05:38:23
Other Links: manifest | tags
Context
2016-06-22
05:09
Fix bugs and typos and add a few useful features check-in: 96fa1e1dd0 user: bohwaz tags: trunk
2016-06-21
05:38
Memory cache check-in: 9f6ac43d67 user: bohwaz tags: trunk
2016-06-05
20:50
Ability to get metadata in an object instead of array. + regexp fix for php 7 check-in: 509873b3c5 user: bohwaz tags: trunk
Changes

Added src/lib/kd2/MemCache.php version [934e9ac79b].

































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php

namespace KD2;

abstract class MemCache
{
	protected $prefix = null;
	protected $default_ttl = null;

	public function __construct($prefix = null, $default_ttl = 0)
	{
		if (!$this->checkSetup())
		{
			throw new \RuntimeException('Required extension is not installed: ' . get_class($this));
		}

		$this->prefix = (string) $prefix;
		$this->default_ttl = (int) $default_ttl;
	}

	abstract public function checkSetup();
	abstract public function get($key);
	abstract public function set($key, $value, $ttl = 0);
	abstract public function delete($key);
	abstract public function exists($key);
	abstract public function inc($key, $step = 1);
	abstract public function dec($key, $step = 1);

	final public function __unset($key)
	{
		return $this->delete($key);
	}

	final public function __isset($key)
	{
		return $this->test($key);
	}

	final public function __get($key)
	{
		return $this->get($key);
	}
	
	final public function __set($key, $value)
	{
		return $this->set($key, $value);
	}
}

Added src/lib/kd2/MemCache_APCu.php version [0c6c077a12].

































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php

namespace KD2;

/**
 * Cache user data with APCu
 *
 * Note that the cache is shared by the same process 
 * and can result in being shared by multiple vhosts
 * or users.
 */
class MemCache_APCu extends MemCache
{
	public function checkSetup()
	{
		return function_exists('apcu_store');
	}

	public function exists($key)
	{
		return apcu_exists($this->prefix . $key);
	}

	public function get($key)
	{
		return apcu_fetch($this->prefix . $key);
	}

	public function set($key, $value, $ttl = 0)
	{
		return apcu_store($this->prefix . $key, $value, $ttl);
	}

	public function inc($key, $step = 1)
	{
		return apcu_inc($this->prefix . $key, (int) $step);
	}

	public function dec($key, $step = 1)
	{
		return apcu_dec($this->prefix . $key, (int) $step);
	}

	public function delete($key)
	{
		return apcu_delete($this->prefix . $key);
	}
}

Added src/lib/kd2/MemCache_XCache.php version [7ed0f78988].







































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php

namespace KD2;

/**
 * Cache data to XCache user cache
 * WARNING: The cache is shared by all users of the same server by default.
 * Use the following php.ini config to have a separate cache for every vhost:
 * xcache.var_namespace_mode = 1
 * xcache.var_namespace = "DOCUMENT_ROOT"
 *
 * See https://xcache.lighttpd.net/ticket/287#comment:13 for details
 */

class MemCache_XCache extends MemCache
{
	public function checkSetup()
	{
		return function_exists('xcache_set');
	}

	public function exists($key)
	{
		return xcache_isset($this->prefix . $key);
	}

	public function get($key)
	{
		return xcache_get($this->prefix . $key);
	}

	public function set($key, $value, $ttl = 0)
	{
		return xcache_set($this->prefix . $key, $value, $ttl);
	}

	public function inc($key, $step = 1)
	{
		return xcache_inc($this->prefix . $key, (int) $step);
	}

	public function dec($key, $step = 1)
	{
		return xcache_dec($this->prefix . $key, (int) $step);
	}

	public function delete($key)
	{
		return xcache_unset($this->prefix . $key);
	}
}