scache_add
Description
bool scache_add(resource session, string path, mixed value)
bool $SCacheConnection->add(string path, mixed value)
scache_add adds value to given path in session private keyspace only if path does not contain previous value.
Functions scache_set, scache_add and scache_replace are all for setting session values. Differencies are :
- scache_set always sets value regardless whether it already exists or not
- scache_add sets value only if it doesn't already exist. In other words scache_add doesn't ever overwrite existing value.
- scache_replace replaces already existing values but newer create new one.
Parameters
session
path
Slash (/) separated path on backend's session tree. Path parameter is not binary safe.
value
Value to be stored. Must be serialize()able.
Return values
TRUE on success, FALSE on failure.
In case of failure, error codes resolvable by scache_lasterr is one of below :
- SCERR_EXIST Path given already exists and won't be replaced.
- SCERR_NO_SESSION Connected session does not exist or has been expired. Connection is not valid any more.
- SCERR_LIMITS_REACHED Partition has exceeded its memory or node limits and new session cannot be created until memory is freed.
- SCERR_NOT_CONNECTED Connection to backend is broken and cannot be reconnected.
- SCERR_PROTOCOL Internal protocol error has occurred when communicating to backend. This indicates something is severely broken.
Examples
<?php /* get connection */ $session = scache_reset('MyEasilyGuessableSecret'); if (!scache_exists($session, 'my/path') && scache_add($session, 'my/path', 'value')) { echo "Mom! I inserted a value!\n"; } if (!scache_add($session, 'my/path', 'another value')) { echo "It did not succeed any more..\n"; } ?>