-
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?
Conversation
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.
The feature sounds reasonable to me. This is currently missing a test though.
@@ -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) { |
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.
apc_cache_t* cache, zend_string *key, const int32_t ttl) { | |
apc_cache_t *cache, zend_string *key, int32_t ttl) { |
Z_PARAM_LONG(ttl) | ||
ZEND_PARSE_PARAMETERS_END(); | ||
|
||
t = apc_time(); |
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.
Unused?
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Unused?
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Why is ttl optional?
return 0; | ||
} | ||
|
||
entry->ctime = t; |
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.
Hm, should this really be setting ctime and not mtime (or neither)?
APCu lacks a nice way to update the TTL of an entry. Currently, you'd have to implement your own critical section, fetch the value of an entry, and then store it back. I think there are many use cases with websites where one would want to create a cache entry with a short life and then extend its lifespan on a subsequent request from the browser.
I think this will be especially useful in combination with apcu_inc, apcu_dec, and apcu_cas. Because calling apcu_store (the only way to extend TTL ATM) after them defeats their purpose.
This PR adds
apcu_set_ttl($key, int $ttl = 0): bool
. If entry with the $key has been successfully updated, function returns true, else, false.