scache_replace

Description

bool scache_replace(resource session, string path, mixed value)
bool $SCacheConnection->replace(string path, mixed value)

scache_replace 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 and all its values freed.

Functions scache_set, scache_add and scache_replace are all for setting session values. Differencies are :

Parameters

session
Session resource returned from scache_open, scache_reset or scache_connect
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 :

Examples

<?php

/* get connection */
$session = scache_reset('MyEasilyGuessableSecret');

scache_set($session, 'my/path', 'oldvalue');
if (scache_exists($session, 'my/path') &&
    scache_replace($session, 'my/path', 'value')) {

    echo "Mom! I did replace it!\n";
}

if (!scache_replace($session, 'my/notexisting/path', 'another value')) {

    echo "It did not succeed any more..\n";
}
?>