scache_shreplace
Description
bool scache_shreplace(resource session, string path, mixed value)
bool $SCacheConnection->shreplace(string path, mixed value)
scache_shreplace is operationally equal to session spesific scache_replace but unlike it, scache_shreplace operates on shared storage that is common and accessible for all clients. Shared storage is for operating data common to all clients and for inter-client communication.
scache_shreplace sets value to given path on session-local storage only if it path previously exists and is not empty. Previous value will be replaced. If previous value was subtree, subtree is destroyed.
Functions scache_shset, scache_shadd and scache_shreplace are all for setting session values. Differencies are :
- scache_shset always sets value regardless whether it already exists or not
- scache_shadd sets value only if it doesn't already exist. In other words scache_shadd doesn't ever overwrite existing value.
- scache_shreplace 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_NOTEXIST Path given does not exist and won't be created.
- SCERR_NO_SESSION Connected session does not exist or has been expired. Connection is not valid any more.
- SCERR_NO_ACCESS Shared keyspace is not allowed on assigned partition.
- 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_shreset('MyEasilyGuessableSecret'); scache_shset($session, 'my/path', 'oldvalue'); if (scache_shexists($session, 'my/path') && scache_shreplace($session, 'my/path', 'value')) { echo "Mom! I did replace it!\n"; } if (!scache_shreplace($session, 'my/notexisting/path', 'another value')) { echo "It did not succeed any more..\n"; } ?>