Coder Social home page Coder Social logo

wfxiang08 / yac Goto Github PK

View Code? Open in Web Editor NEW

This project forked from laruence/yac

0.0 2.0 0.0 149 KB

A fast shared memory user data cache for PHP

License: Other

C 82.60% C++ 2.67% M4 3.66% JavaScript 0.93% PHP 9.49% Shell 0.03% CMake 0.61%
php cache memory-mapping

yac's Introduction

#Yac - Yet Another Cache Build Status

Yac is a shared and lockless memory user data cache for PHP.

it can be used to replace APC or local memcached.

Experimental

Yac is lockless, that means, there might be a chance that you will get a wrong data(depends on how many key slots are allocated and how many keys are stored), so you'd better make sure that your product is not very sensitive to that.

According to the test(https://github.com/laruence/yac/blob/master/tests/yac_conflict.php), there is 1/10000000 chance you will get a wrong data, however this test script is designed to make conflicts, in the real application, this chance must be much less.

Requirement

  • PHP 5.2 +

Install

$/path/to/phpize
$./configure --with-php-config=/path/to/php-config
$make && make install

Note

  1. Yac is a lockless cache, you should try to avoid or reduce the probability of multiple processes set one same key
  2. Yac use partial crc, you'd better re-arrange your cache content, place the most mutable bytes at the head or tail

Restrictions

  1. Cache key cannot be longer than 48 (YAC_MAX_KEY_LEN) bytes
  2. Cache Value cannot be longer than 64M (YAC_MAX_VALUE_RAW_LEN) bytes
  3. Cache Value after compressed cannot be longer than 1M (YAC_MAX_VALUE_COMPRESSED_LEN) bytes

InIs

yac.enable = 1

yac.keys_memory_size = 4M ; 4M can get 30K key slots, 32M can get 100K key slots

yac.values_memory_size = 64M

yac.compress_threshold = -1

yac.enable_cli = 0 ; whether enable yac with cli, default 0

Constants

YAC_VERSION

YAC_MAX_KEY_LEN = 48 ; if your key is longer than this, maybe you can use md5 result as the key

YAC_MAX_VALUE_RAW_LEN = 64M

YAC_MAX_VALUE_COMPRESSED_LEN = 1M

Methods

Yac::__construct

   Yac::__construct([string $prefix = ""])

Constructor of Yac, you can specify a prefix which will used to prepend to any keys when doing set/get/delete

<?php
   $yac = new Yac("myproduct_");
?>

Yac::set

   Yac::set($key, $value[, $ttl])
   Yac::set(array $kvs[, $ttl])

Store a value into Yac cache, keys are cache-unique, so storing a second value with the same key will overwrite the original value.

<?php
$yac = new Yac();
$yac->set("foo", "bar");
$yac->set(
    array(
        "dummy" => "foo",
        "dummy2" => "foo",
        )
    );
?>

Yac::get

   Yac::get(array|string $key)

Fetches a stored variable from the cache. If an array is passed then each element is fetched and returned.

<?php
$yac = new Yac();
$yac->set("foo", "bar");
$yac->set(
    array(
        "dummy" => "foo",
        "dummy2" => "foo",
        )
    );
$yac->get("dummy");
$yac->get(array("dummy", "dummy2"));
?>

Yac::delete

   Yac::delete(array|string $keys[, $delay=0])

Removes a stored variable from the cache. If delay is specified, then the value will be deleted after $delay seconds.

Yac::flush

   Yac::flush()

Immediately invalidates all existing items. it doesn't actually free any resources, it only marks all the items as invalid.

Yac::info

   Yac::info(void)

Get cache info

<?php
  ....
  var_dump($yac->info());
  /* will return an array like:
  array(11) {
      ["memory_size"]=> int(541065216)   
      ["slots_memory_size"]=> int(4194304)
      ["values_memory_size"]=> int(536870912)
      ["segment_size"]=> int(4194304)     
      ["segment_num"]=> int(128)
      ["miss"]=> int(0)
      ["hits"]=> int(955)
      ["fails"]=> int(0)
      ["kicks"]=> int(0)
      ["slots_size"]=> int(32768)
      ["slots_used"]=> int(955)
  }
  */

yac's People

Contributors

laruence avatar philzen avatar remicollet avatar rlerdorf avatar shukean avatar walu avatar weltling avatar zxcvdavid avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.