Skip to content
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

Cache Optimization + bug fixes #1093

Merged
merged 22 commits into from Aug 15, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Removed not used allocs
  • Loading branch information
sjinks committed Aug 15, 2013
commit f87520518fd78cdaa4e4e18f794bacb84ada48ee
6 changes: 1 addition & 5 deletions ext/cache/backend/apc.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Apc, save){
zval *last_lifetime = phalcon_fetch_nproperty_this(this_ptr, SL("_lastLifetime"), PH_NOISY_CC);

if (Z_TYPE_P(last_lifetime) == IS_NULL) {
PHALCON_INIT_VAR(ttl);
PHALCON_OBS_VAR(ttl);
phalcon_call_method_p0_ex(ttl, &ttl, frontend, "getlifetime");
}
else {
Expand Down Expand Up @@ -333,10 +333,6 @@ PHP_METHOD(Phalcon_Cache_Backend_Apc, exists){

phalcon_fetch_params(1, 0, 2, &key_name, &lifetime);

if (!lifetime) {
PHALCON_INIT_VAR(lifetime);
}

if (!key_name || Z_TYPE_P(key_name) == IS_NULL) {
last_key = phalcon_fetch_nproperty_this(this_ptr, SL("_lastKey"), PH_NOISY_CC);
} else {
Expand Down
33 changes: 12 additions & 21 deletions ext/cache/backend/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,17 +403,13 @@ PHP_METHOD(Phalcon_Cache_Backend_File, queryKeys){
PHP_METHOD(Phalcon_Cache_Backend_File, exists){

zval *key_name = NULL, *lifetime = NULL, *last_key, *options;
zval *cache_dir, *cache_file, *frontend, *timestamp;
zval *ttl = NULL, *modified_time, *difference, *not_expired;
zval *cache_dir, *cache_file, *frontend;
zval *tmp, *modified_time;

PHALCON_MM_GROW();

phalcon_fetch_params(1, 0, 2, &key_name, &lifetime);

if (!lifetime) {
PHALCON_INIT_VAR(lifetime);
}

if (!key_name || Z_TYPE_P(key_name) == IS_NULL) {
last_key = phalcon_fetch_nproperty_this(this_ptr, SL("_lastKey"), PH_NOISY_CC);
} else {
Expand All @@ -433,32 +429,27 @@ PHP_METHOD(Phalcon_Cache_Backend_File, exists){
PHALCON_CONCAT_VV(cache_file, cache_dir, last_key);

if (phalcon_file_exists(cache_file TSRMLS_CC) == SUCCESS) {
long int mtime, ttl;

frontend = phalcon_fetch_nproperty_this(this_ptr, SL("_frontend"), PH_NOISY_CC);

/**
* Check if the file has expired
*/
PHALCON_INIT_VAR(timestamp);
ZVAL_LONG(timestamp, (long) time(NULL));
if (Z_TYPE_P(lifetime) == IS_NULL) {
PHALCON_INIT_VAR(ttl);
phalcon_call_method(ttl, frontend, "getlifetime");
if (!lifetime || Z_TYPE_P(lifetime) == IS_NULL) {
PHALCON_OBS_VAR(tmp);
phalcon_call_method_p0_ex(tmp, &tmp, frontend, "getlifetime");

ttl = likely(Z_TYPE_P(tmp) == IS_LONG) ? Z_LVAL_P(tmp) : phalcon_get_intval(tmp);
} else {
PHALCON_CPY_WRT(ttl, lifetime);
ttl = likely(Z_TYPE_P(lifetime) == IS_LONG) ? Z_LVAL_P(lifetime) : phalcon_get_intval(lifetime);
}

PHALCON_INIT_VAR(modified_time);
phalcon_filemtime(modified_time, cache_file TSRMLS_CC);
mtime = likely(Z_TYPE_P(modified_time) == IS_LONG) ? Z_LVAL_P(modified_time) : phalcon_get_intval(modified_time);

PHALCON_INIT_VAR(difference);
sub_function(difference, timestamp, ttl TSRMLS_CC);

PHALCON_INIT_VAR(not_expired);
is_smaller_function(not_expired, difference, modified_time TSRMLS_CC);
if (PHALCON_IS_TRUE(not_expired)) {
/**
* We only return true if the file exists and it did not expired
*/
if (mtime + ttl > (long int)time(NULL)) {
RETURN_MM_TRUE;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ext/cache/backend/libmemcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, exists){
memcache = phalcon_fetch_nproperty_this(this_ptr, SL("_memcache"), PH_NOISY_CC);
}

PHALCON_INIT_VAR(value);
PHALCON_OBS_VAR(value);
phalcon_call_method_p1_ex(value, &value, memcache, "get", last_key);
RETVAL_BOOL(PHALCON_IS_NOT_FALSE(value));
}
Expand Down
8 changes: 4 additions & 4 deletions ext/cache/backend/memcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ PHP_METHOD(Phalcon_Cache_Backend_Memcache, _connect){
return;
}

PHALCON_INIT_VAR(success);
PHALCON_OBS_VAR(success);
if (zend_is_true(persistent)) {
phalcon_call_method_p2(success, memcache, "pconnect", host, port);
phalcon_call_method_p2_ex(success, &success, memcache, "pconnect", host, port);
} else {
phalcon_call_method_p2(success, memcache, "connect", host, port);
phalcon_call_method_p2_ex(success, &success, memcache, "connect", host, port);
}

if (!zend_is_true(success)) {
Expand Down Expand Up @@ -475,7 +475,7 @@ PHP_METHOD(Phalcon_Cache_Backend_Memcache, exists){
memcache = phalcon_fetch_nproperty_this(this_ptr, SL("_memcache"), PH_NOISY_CC);
}

PHALCON_INIT_VAR(value);
PHALCON_OBS_VAR(value);
phalcon_call_method_p1_ex(value, &value, memcache, "get", last_key);
RETVAL_BOOL(PHALCON_IS_NOT_FALSE(value));
}
Expand Down