StumbleCache is a mmap backed caching extension for PHP
C PHP
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
btree
tests
.gitignore
LICENSE
README.rest
config.m4
php_stumblecache.h
stumblecache.c

README.rest

StumbleCache

Stumblecache is a high performance shared memory cache that scales to tens of gigabytes of cache, thousands of requests per second, and high update rates. It was created to allow Stumbleupon to cache large amounts of short ttl url data on our webserver and worker tiers.

You can think of it as a replacement for the user caching portion of apc, though different tradeoffs have been made and stumblecache will be less space efficient in most cases.

  • MMAP based
  • Fixed allocations ie. 500k 2k cache blocks

API

INI

  • stumblecache.location: the path where all the caches are stored

Class: StumbleCacheOptions

__construct( nrOfItems, itemSize )

  • nrOfItems is the maximum number of items in the cache.
  • itemSize is the size of each item in the cache.
    rounded up to nearest 4kb (or pagesize)

The cache will use nrOfItems * itemSize amount of memory, plus some overhead.

Class: StumbleCache

__construct ( cacheRef )

  • cacheRef: string: name of the cache

Cache Layout

/tmp/<cache-id>.scstats

/tmp/<cache-id>.scache

page 0: meta-data

  • cache file version: 4 bytes
  • item size: 4 bytes
  • nr of items: 4 bytes
  • next data page: 4 bytes

page 1-x: index, b-tree

  • b-tree node: 1023 keys, 1024 children

    • header:

      • leaf: yes/no byte
      • nrOfKeys: 1-1023 2 bytes
    • keys

      • key: 8 bytes

      • value idx: 4 bytes number = idx into data block

      • expire ts: 2 bytes

      • flags: 2 bytes

        • in use: 1 bit

License

This extension is released under the PHP 3.01 license, see LICENSE file for details

This product includes PHP software, freely available from <http://www.php.net/software/>