wiki:XcacheApi

Version 1 (modified by mOo, 9 years ago) (diff)

--

XCache API exported to PHP script

Constants

XC_TYPE_PHP: Cache Type = php opcode
XC_TYPE_VAR: Cache Type = variable data

Common Used Functions

mixed xcache_get(string name)
bool  xcache_set(string name, mixed value [, int ttl])
bool  xcache_isset(string name)
bool  xcache_unset(string name)
int   xcache_inc(string name [, int value [, int ttl]])
int   xcache_dec(string name [, int value [, int ttl]])

Examples:

  • Simple Counter
    This guest book has been visited <?php echo xcache_inc("count"); ?> times.
    
  • Cacher
    <?php
    function load_abc_data()
    {
      if (xcache_isset("cache")) {
        return xcache_get("cache");
      }
      $fp = fopen(TMPDIR . "/cache.lock");
      flock($fp, LOCK_EX);
      // check AGAIN after we get the lock
      if (xcache_isset("cache")) {
        fclose($fp);
        return xcache_get("cache");
      }
      mysql_query .... and get $data
      xcache_set("cache", $data, 120); // save for 2 minutes
      fclose($fp);
      return $data;
    }
    

Administrator Functions

int    xcache_count(int type)
array  xcache_info(int type, int id)
array  xcache_list(int type, int id)
array  xcache_clear_cache(int type, int id)
string xcache_coredump(int op_type)

an admin php script will be available in XCache source repo later, that use admin functions.

De/Assembler? Opcode Functions

string xcache_asm(string filename)
string xcache_dasm_file(string filename)
string xcache_dasm_string(string code)
string xcache_encode(string filename)
bool   xcache_decode(string filename)

string xcache_get_op_type(int op_type)
string xcache_get_data_type(int type)
string xcache_get_opcode(int opcode)
string xcache_get_op_spec(int op_type)
string xcache_get_opcode_spec(int opcode)
mixed  xcache_get_special_value(zval value)
string xcache_is_autoglobal(string name)