ServerCache Class
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 optionalThe folder to store the file-based cache
-
[server='127.0.0.1']
String optionalThe IP of the memcache server we're connecting to
-
[port='11211']
String optionalThe port of the memcache server
-
[expiresDefault=604800]
Int optionalThe default time before caches expire (defaults to 7 days)
Item Index
Properties
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
StringThe name of the context
-
[expires=-1]
Int optionalHow many seconds before this expires, defaults to expiresDefault
delete
-
key
Remove a value by a key
Parameters:
-
key
StringThe key of the item to remove
Returns:
if successful, false on failure
destroy
()
Destroy the instance and don't use after this, or re-init
flushContext
-
context
Delete a context (which is a group of related keys)
Parameters:
-
context
StringThe name of the context
Returns:
if we successfully deleted the context
pushContext
-
context
-
key
Save a collection of the cached keys to make it easier to clear later on
read
-
The
-
[output=false]
Read an item back from the cache
Parameters:
Returns:
Return false if we can't read it, or it doesn't exist
save
-
key
-
value
-
[context=null]
-
[expires=-1]
Save and item to the server
Parameters:
Returns:
If successfully saved
setEnabld
-
enabled
If the cache is enabled
Parameters:
-
enabled
BooleanIf this cache should be enabled
Properties
_memcache
Memcache
private
The memcache connection
expiresDefault
Int
private
Set the expiration time (default 7 days)