API Documentation for: 1.1.1
Show:

ServerCache Class

Namespace: Canteen\Server

A server cache to reduce server load this will try to use Memcache if available or fallback to a file-base approach.
Located in the namespace Canteen\Server.

Constructor

ServerCache

(
  • [cacheDirectory=null]
  • [server='127.0.0.1']
  • [port='11211']
  • [expiresDefault=604800]
)

Parameters:

  • [cacheDirectory=null] String optional

    The folder to store the file-based cache

  • [server='127.0.0.1'] String optional

    The IP of the memcache server we're connecting to

  • [port='11211'] String optional

    The port of the memcache server

  • [expiresDefault=604800] Int optional

    The default time before caches expire (defaults to 7 days)

Methods

addContext

(
  • context
  • [expires=-1]
)

Add a context, or group to the cache to make it easier to flush certain things at once

Parameters:

  • context String

    The name of the context

  • [expires=-1] Int optional

    How many seconds before this expires, defaults to expiresDefault

delete

(
  • key
)
Boolean

Remove a value by a key

Parameters:

  • key String

    The key of the item to remove

Returns:

Boolean:

if successful, false on failure

destroy

()

Destroy the instance and don't use after this, or re-init

flush

() Boolean

Remove all of the items from the server

Returns:

Boolean:

if successfully flushed

flushContext

(
  • context
)
Boolean

Delete a context (which is a group of related keys)

Parameters:

  • context String

    The name of the context

Returns:

Boolean:

if we successfully deleted the context

getEnabled

() Boolean

Get if this cache is enabled

Returns:

Boolean:

if the cache is enabled

pushContext

(
  • context
  • key
)

Save a collection of the cached keys to make it easier to clear later on

Parameters:

  • context String

    The name of the context

  • key String

    The key to save

read

(
  • The
  • [output=false]
)
Mixed

Read an item back from the cache

Parameters:

  • The String

    key of the item

  • [output=false] Boolean optional

    If the file should be output directly (better memory management)

Returns:

Mixed:

Return false if we can't read it, or it doesn't exist

save

(
  • key
  • value
  • [context=null]
  • [expires=-1]
)
Boolean

Save and item to the server

Parameters:

  • key String

    The key of the item

  • value Mixed

    The value of the item

  • [context=null] String optional

    If we should compress the item (defaults to true)

  • [expires=-1] Int optional

    How many seconds before this expires, defaults to expiresDefault

Returns:

Boolean:

If successfully saved

setEnabld

(
  • enabled
)

If the cache is enabled

Parameters:

  • enabled Boolean

    If this cache should be enabled

Properties

_cacheDirectory

String private

The path to the cache directory

_enabled

Boolean private

If the cache is turned on or not

_memcache

Memcache private

The memcache connection

_useFileSystem

Boolean private

use the file system to cache files

expiresDefault

Int private

Set the expiration time (default 7 days)