GithubHelp home page GithubHelp logo

pleebe / cache Goto Github PK

View Code? Open in Web Editor NEW

This project forked from foolcode/cache

0.0 2.0 1.0 43 KB

Rich people's caching package. We want everything from dummy to permanent.

License: Other

PHP 100.00%

cache's Introduction

Heavy duty caching package, meant for serious sites needing serious caching powers.

Requires PHP 5.4.

The gist

You must give a configuration object to an instance of cache.

<?php
Cache::instantiate(Config::forgeApc());
Cache::item('test')->set($value);
Cache::item('test')->get();
?>

And this is all if you use APC.

Storages

Currently bundled storages:

  • APC
  • Memcached
  • DB (Doctrine DBAL) (permanent storage, great for configurations)
  • Dummy (always returns not found)
  • File
  • Volatile (uses PHP Arrays and gets wiped on the end of the process)

Formats

We added several formats that might sound useless. We need the formats to be compatible with extraneous software.

Currently bundled formats:

  • ArrayJson (stores the json wrapped as array)
  • ObjectJson (stores the json wrapped as object)
  • SmartJson (uses an object to store the kind of json)
  • Plain
  • Serialized

Configuration

You can create a new configuration in two ways:

<?php
$config = Config::forgeMemcached();
// or
$config = new \Foolz\Cache\Config\Memcached;
?>

IDE hints will appear, helping you configuring the storage. You can also look in the folder classes/Foolz/Cache/Config for the configurations available.

Base configuration methods

  • $config->getStorage()

    Returns the name of the storage

  • $config->setFormat($format)

    Set one of the formats: array_json, object_json, smart_json, plain, serialized.

  • __$config->getFormat()

    Returns the name of the format

  • $config->setPrefix($prefix)

    Set a prefix for the stored items

  • $config->getPrefix()

    Get the prefix for the stored items

  • $config->setThrow($bool = false)

    Pass true if you want failed cache GETs to throw an exception. False if you prefer a fallback value. False by default.

  • $config->getThrow()

    True if GETs will throw an exception, false otherwise.

Instantiation

The Cache package features an instance system.

  • Cache::instantiate(\Foolz\Cache\Config $config, $instance_name = 'default')

    Create a new link for the caching backend.

  • Cache::destroy($instance_name)

    Destroys the link for the cache backend.

  • $item = Cache::forge($instance_name = 'default')

    Returns an instance of the link.

  • $item = Cache::item($key, $instance_name = 'default)

    Creates an instance paired with a key.

  • $item->getConfig()

    Returns the configuration object.

  • $item->getEngine()

    Returns the raw storage engine class.

  • $item->getKey()

    Returns the key for the item.

  • $item->set($value, $expiration = 0)

    Sets a value. Expiration is seconds from now.

  • $item->get()

    Returns the stored value. Returns \Foolz\Cache\Void if the value is not found. Throws \OutOfBoundsException if the Throws setting is enabled and the value is not found.

  • $item->delete()

    Delete a stored value.

  • $item->flush()

    Deletes all the entries in the engine.

cache's People

Contributors

oohnoitz avatar pleebe avatar woxxy avatar

Watchers

 avatar  avatar

Forkers

magyarchan

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.