-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/apcu_set_ttl Add function to set the TTL of an existing entry atomically #507
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -273,7 +273,7 @@ PHP_APCU_API int APC_UNSERIALIZER_NAME(php) (APC_UNSERIALIZER_ARGS) | |
result = php_var_unserialize(value, &tmp, buf + buf_len, &var_hash); | ||
PHP_VAR_UNSERIALIZE_DESTROY(var_hash); | ||
BG(serialize_lock)--; | ||
|
||
if (!result) { | ||
php_error_docref(NULL, E_NOTICE, "Error at offset %td of %zd bytes", tmp - buf, buf_len); | ||
ZVAL_NULL(value); | ||
|
@@ -539,6 +539,34 @@ PHP_APCU_API zend_bool apc_cache_store( | |
return ret; | ||
} /* }}} */ | ||
|
||
/* {{{ apc_cache_set_ttl */ | ||
PHP_APCU_API zend_bool apc_cache_update_ttl( | ||
apc_cache_t* cache, zend_string *key, const int32_t ttl) { | ||
apc_cache_entry_t *entry; | ||
zend_bool retval = 0; | ||
time_t t = apc_time(); | ||
|
||
if (!cache) { | ||
return 0; | ||
} | ||
|
||
if (!apc_cache_rlock(cache)) { | ||
return 0; | ||
} | ||
|
||
entry = apc_cache_rlocked_find_nostat(cache, key, t); | ||
if (!entry) { | ||
apc_cache_runlock(cache); | ||
return 0; | ||
} | ||
|
||
entry->ctime = t; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, should this really be setting ctime and not mtime (or neither)? |
||
entry->ttl = ttl; | ||
|
||
apc_cache_runlock(cache); | ||
return 1; | ||
} /* }}} */ | ||
|
||
#ifndef ZTS | ||
/* {{{ data_unserialize */ | ||
static zval data_unserialize(const char *filename) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -517,6 +517,26 @@ PHP_FUNCTION(apcu_store) { | |
} | ||
/* }}} */ | ||
|
||
/* {{{ proto bool apc_cache_update_ttl(mixed key [, long ttl ]) | ||
*/ | ||
PHP_FUNCTION(apcu_set_ttl) { | ||
zend_string *key; | ||
zend_long ttl = 0L; | ||
zval *success = NULL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused? |
||
time_t t; | ||
|
||
ZEND_PARSE_PARAMETERS_START(1, 2) | ||
Z_PARAM_STR(key) | ||
Z_PARAM_OPTIONAL | ||
Z_PARAM_LONG(ttl) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is ttl optional? |
||
ZEND_PARSE_PARAMETERS_END(); | ||
|
||
t = apc_time(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused? |
||
|
||
RETURN_BOOL(apc_cache_update_ttl(apc_user_cache, key, ttl)); | ||
} | ||
/* }}} */ | ||
|
||
/* {{{ proto int apcu_add(mixed key, mixed var [, long ttl ]) | ||
*/ | ||
PHP_FUNCTION(apcu_add) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.