Пример #1
0
/* {{{ apc_iterator_item */
static apc_iterator_item_t* apc_iterator_item_ctor(apc_iterator_t *iterator, apc_cache_slot_t **slot_pp) {
    zval zvalue;
    apc_cache_slot_t *slot = *slot_pp;
    apc_context_t ctxt = {0, };
    apc_iterator_item_t *item = ecalloc(1, sizeof(apc_iterator_item_t));

    array_init(&item->value);

	item->key = slot->key.str;

    if (APC_ITER_TYPE & iterator->format) {
		add_assoc_string_ex(&item->value, "type", sizeof("type")-1, "user");
	}

	if (APC_ITER_KEY & iterator->format) {
		add_assoc_str(&item->value, "key", zend_string_copy(item->key));
	}

    if (APC_ITER_VALUE & iterator->format) {
    	apc_cache_make_context(
    		apc_user_cache, &ctxt, APC_CONTEXT_NOSHARE, APC_UNPOOL, APC_COPY_OUT, 0);
    	ZVAL_UNDEF(&zvalue);
        apc_cache_fetch_zval(&ctxt, &zvalue, &slot->value->val);
        add_assoc_zval(&item->value, "value", &zvalue);
        apc_pool_destroy(ctxt.pool);
    }

    if (APC_ITER_NUM_HITS & iterator->format) {
        add_assoc_long(&item->value, "num_hits", slot->nhits);
    }
    if (APC_ITER_MTIME & iterator->format) {
        add_assoc_long(&item->value, "mtime", slot->key.mtime);
    }
    if (APC_ITER_CTIME & iterator->format) {
        add_assoc_long(&item->value, "creation_time", slot->ctime);
    }
    if (APC_ITER_DTIME & iterator->format) {
        add_assoc_long(&item->value, "deletion_time", slot->dtime);
    }
    if (APC_ITER_ATIME & iterator->format) {
        add_assoc_long(&item->value, "access_time", slot->atime);
    }
    if (APC_ITER_REFCOUNT & iterator->format) {
        add_assoc_long(&item->value, "ref_count", slot->value->ref_count);
    }
    if (APC_ITER_MEM_SIZE & iterator->format) {
        add_assoc_long(&item->value, "mem_size", slot->value->mem_size);
    }
    if (APC_ITER_TTL & iterator->format) {
        add_assoc_long(&item->value, "ttl", slot->value->ttl);
    }

    return item;
}
Пример #2
0
static inline zend_bool apc_cache_fetch_internal(apc_cache_t* cache, zend_string *key, apc_cache_entry_t *entry, time_t t, zval **dst) {
	/* context for copying out */
	apc_context_t ctxt = {0, };

	/* create unpool context */
	if (apc_cache_make_context(cache, &ctxt, APC_CONTEXT_NOSHARE, APC_UNPOOL, APC_COPY_OUT, 0)) {

		/* copy to destination */
		apc_cache_fetch_zval(&ctxt, *dst, &entry->val);

		/* release entry */
		apc_cache_release(cache, entry);

		/* destroy context */
		apc_cache_destroy_context(&ctxt );

		return 1;
	}

	return 0;
}
Пример #3
0
/* {{{ apc_cache_store */
PHP_APCU_API zend_bool apc_cache_store(apc_cache_t* cache, zend_string *strkey, const zval *val, const int32_t ttl, const zend_bool exclusive) {
    apc_cache_entry_t *entry;
    apc_cache_key_t key;
    time_t t;
    apc_context_t ctxt={0,};
    zend_bool ret = 0;

    t = apc_time();

	/* initialize a context suitable for making an insert */
    if (apc_cache_make_context(cache, &ctxt, APC_CONTEXT_SHARE, APC_SMALL_POOL, APC_COPY_IN, 0)) {

        /* initialize the key for insertion */
        if (apc_cache_make_key(&key, strkey)) {

            /* run cache defense */
            if (!apc_cache_defense(cache, &key)) {
                
                /* initialize the entry for insertion */
                if ((entry = apc_cache_make_entry(&ctxt, &key, val, ttl))) {
                
                    /* execute an insertion */
                    if (apc_cache_insert(cache, &key, entry, &ctxt, t, exclusive)) {
                        ret = 1;
                    }
                }
            }
        }

        /* in any case of failure the context should be destroyed */
        if (!ret) {
            apc_cache_destroy_context(&ctxt);
        }
    }

    return ret;
} /* }}} */