Esempio n. 1
0
static void cache_module( const char *filename, aptime time, value main ) {
	cache *c = (cache*)local_get(cache_root), *prev = NULL;
	value fname = alloc_string(filename);
	while( c != NULL ) {
		if( val_compare(fname,c->file) == 0 ) {
			if( main == NULL ) {
				if( prev == NULL )
					local_set(cache_root,c->next);
				else
					prev->next = c->next;
				free_root((value*)c);
			} else {
				c->main = main;
				c->time = time;
			}
			return;
		}
		prev = c;
		c = c->next;
	}
	c = (cache*)alloc_root(sizeof(struct cache) / sizeof(value));
	c->file = fname;
	c->main = main;
	c->time = time;
	c->hits = 0;
	c->next = (cache*)local_get(cache_root);
	local_set(cache_root,c);
}
Esempio n. 2
0
static value cache_find( request_rec *r ) {
	cache *c = (cache*)local_get(cache_root);
	cache *prev = NULL;
	value fname = alloc_string(r->filename);
	while( c != NULL ) {
		if( val_compare(fname,c->file) == 0 ) {
			if( config.use_cache && FTIME(r) == c->time ) {
				c->hits++;
				return c->main;
			}
			if( prev == NULL )
				local_set(cache_root,c->next);
			else
				prev->next = c->next;
			free_root((value*)c);
			// try to lower memory partitioning
			// when a module is updated
			c = NULL;
			gc_major();
			break;
		}
		prev = c;
		c = c->next;
	}
	return NULL;
}
Esempio n. 3
0
int main (int argc, const char * argv[]) {
	struct settings *settings = local_config();
	settings->hash_power = 0;
	settings->prealloc = true;
	settings->evict_opt = EVICT_LRU;
	settings->maxbytes = 200 * 1024 * 1024;
	settings->slab_size = 1024 * 1024;
	settings->use_freeq = true;
	settings->use_lruq = true;
	settings->profile_last_id = 12;
	int i = 0, j = 0, n = 0;
	for (i = 1; i < 13; i++) {
		settings->profile[i] = 100 * i;
	}
	bool result = local_start();
	if (result) printf("cache started\n");
	else {
		printf("cache started fail\n");
		return 1;
	}
	char *key = (char*)malloc(8);
	char *value = (char*)malloc(900);
	for (i = 0; i < 10000; i++) {
		for (j = 0; j < 10000; j++) {
			int *ptr = (int*)key;
			*ptr = i;
			*(ptr++) = j;
			n = i + j;
			n = (n % 9) * 100 + 50;
			ptr = (int*)value;
			*ptr = i;
			*(ptr + n - 4) = j;
			result = local_put(key, 8, 10, value, n);
			if (!result) {
				printf("cache put item fail\n");
				printf("%d %d\n", i, j);
				return 1;
			}
			struct item *res = local_get(key, 8);
			if (res == NULL || res->nbyte != n) {
				printf("cache get item fail\n");
				printf("%d %d\n", i, j);
				return 1;
			}
			char *data = item_data(res);
			if (*((int*)data) != i) {
				printf("cache get value fail\n");
				printf("%d %d\n", i, j);
				return 1;
			}
		}
	}
	return 0;
}
Esempio n. 4
0
value cgi_command( value v ) {
	val_check(v,string);
	if( strcmp(val_string(v),"stats") == 0 )
		return neko_stats_build(neko_vm_current());
	if( strcmp(val_string(v),"cache") == 0 ) {
		cache *c = (cache*)local_get(cache_root);
		value l = val_null;
		while( c != NULL ) {
			value a = alloc_array(4);
			val_array_ptr(a)[0] = c->file;
			val_array_ptr(a)[1] = c->main;
			val_array_ptr(a)[2] = alloc_int(c->hits);
			val_array_ptr(a)[3] = l;
			l = a;
			c = c->next;
		}
		return l;
	}
	neko_error();
}