コード例 #1
0
ファイル: apc_cache.c プロジェクト: Cum6upck/apcu
static int apc_load_data(apc_cache_t* cache, const char *data_file)
{
    char *p;
    char key[MAXPATHLEN] = {0,};
    unsigned int key_len;
    zval data;

    p = strrchr(data_file, DEFAULT_SLASH);

    if(p && p[1]) {
        strlcpy(key, p+1, sizeof(key));
        p = strrchr(key, '.');

        if(p) {
            p[0] = '\0';
            key_len = strlen(key);

            data = data_unserialize(data_file);
            if(Z_TYPE(data) != IS_UNDEF) {
				zend_string *name = zend_string_init(key, key_len, 0);
                apc_cache_store(
					cache, name, &data, 0, 1);
				zend_string_release(name);
				zval_dtor(&data);
            }
            return 1;
        }
    }

    return 0;
}
コード例 #2
0
ファイル: memoize.c プロジェクト: krakjoe/memoize
/* {{{ */
static int php_memoize_return(zend_execute_data *execute_data) {
	zend_long ttl = 0;
	const zend_function *fbc = EX(func);

	if (MG(ini.enabled) && php_memoize_is_memoizing(fbc, &ttl)) {
		zend_string *key = php_memoize_key(
			&EX(This),
			fbc, EX_NUM_ARGS(), EX_VAR_NUM(0));

		if (key) {
			zval *return_value;

			if (EX(opline)->op1_type & IS_CONST) {
				return_value = EX_CONSTANT(EX(opline)->op1);
			} else {
				return_value = EX_VAR(EX(opline)->op1.var);
			}

			apc_cache_store(php_memoize_cache, key, return_value, ttl, 1);

			if (EG(exception)) {
				zend_clear_exception();
			}

			zend_string_release(key);
		}
	}
	
	if (zend_return_function) {
		return zend_return_function(execute_data);
	}

	return ZEND_USER_OPCODE_DISPATCH;
} /* }}} */
コード例 #3
0
ファイル: apcups.c プロジェクト: krakjoe/apcu-ps
static inline PS_WRITE_FUNC(apcu) 
{
    zval zcontent;
    
    ZVAL_STRINGL(&zcontent, val, vallen+1, 0);

    apc_cache_store(
        apc_ps_cache, (char*) key, strlen(key)+1, &zcontent, 0, 0 TSRMLS_CC);

    return SUCCESS;
}
コード例 #4
0
ファイル: apc_cache.c プロジェクト: Cum6upck/apcu
/* {{{ apc_cache_update */
PHP_APCU_API zend_bool apc_cache_update(apc_cache_t* cache, zend_string *key, apc_cache_updater_t updater, void* data)
{
    apc_cache_slot_t** slot;
    apc_cache_entry_t tmp_entry;
	
    zend_bool retval = 0;
    zend_ulong h, s;

    if(apc_cache_busy(cache))
    {
        /* cannot service request right now */ 
        return 0;
    }

    /* calculate hash */
    apc_cache_hash_slot(cache, key, &h, &s);
	
	/* lock header */
	APC_LOCK(cache->header);

	/* find head */
    slot = &cache->slots[s];

    while (*slot) {
		/* check for a match by hash and identifier */
        if ((h == ZSTR_HASH((*slot)->key.str)) &&
            memcmp(ZSTR_VAL((*slot)->key.str), ZSTR_VAL(key), ZSTR_LEN(key)) == SUCCESS) {
			/* attempt to perform update */
            switch(Z_TYPE((*slot)->value->val)) {
                case IS_ARRAY:
                case IS_OBJECT:
                {
                    if(cache->serializer) {
                        retval = 0;
                        break;
                    }
                }

                /* break intentionally omitted */

                default:
                {
					/* executing update */
                    retval = updater(cache, (*slot)->value, data);
					/* set modified time */
                    (*slot)->key.mtime = apc_time();
                }
                break;
            }
			/* unlock header */
			APC_UNLOCK(cache->header);

            return retval;
        }

		/* set next slot */
        slot = &(*slot)->next;
	}

	/* unlock header */
	APC_UNLOCK(cache->header);

	/* failed to find matching entry, create it */
	ZVAL_LONG(&tmp_entry.val, 0);
	updater(cache, &tmp_entry, data);

	if(apc_cache_store(cache, key, &tmp_entry.val, 0, 0)) {
		return 1;
	}

    return 0;
}