Posts tagged with ‘Windows’

0

WinCache PHP Class

I’ve developed a new class for WinCache that wraps around the wincache_ucache* functions. The goal of this class/project is to improve — and add to — the functionality and usability of WinCache’s User Cache feature.

Basic Usage

Below is a quick code example of how this class simplifies the way in which a developer can take advantage of the user cache.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
 * Get Cache Object
 */

$cacheObj = DDWinUCache::getInstance();
/**
 * Cache Data
 */

$cacheObj->set('foo', 'bar');
$cacheObj->set('bar', 'candy');
$cacheObj->set('hello_world', 'we did it!');
$cacheObj->set('apple_red_core', 'simple tagging');
/**
 * Delete Cache Entries
 */

$cacheObj->delete('*or*'); // array('apple_red_core', 'hello_world');
/**
 * Get Cached Data
 */

$cacheObj->get('foo'); // "bar"

New Features

Within this class I’ve greatly improved the functionality of the delete method. I’ve also made getting information about the user cache simpler by creating accessor methods for all user cache related data. And to top it all off I’ve implemented ArrayAccess to push the simplicity over the edge.

Improved Delete

Arguably the biggest feature of this class is the ability to delete cache entries via three methods.

1
2
3
4
5
6
7
8
9
10
11
12
13
/**
 * Traditional
 */

$cacheObj->delete('this_is_a_test_entry');
/**
 * Wild Cards '*' and '?'
 */

$cacheObj->delete('this*');
$cacheObj->delete('this?is?a?test?entry');
/**
 * Regular Expression (PCRE)
 */

$cacheObj->delete('/^this.*?entry$/i');

Accessor Methods

I’ve mapped all the data available via the arrays returned by wincache_ucahce_info() and wincache_ucahce_meminfo() into accessor methods. I’ve also added two more derived methods that can be used to help control the user cache — getMemoryUsed() and getMemoryUsedPercent()

(more…)