start to integrate separated cache
This commit is contained in:
parent
d51b06a396
commit
8b7af6781f
@ -206,7 +206,7 @@ int verify_init(cfgl_t *cfg, void **handle) {
|
||||
cache_file = findcfglx(vch->cfg, "cache_file", "verifier_cache");
|
||||
|
||||
if (1 == cache_enabled) {
|
||||
vch->cache = cache_init(cache_file, cache_expiry);
|
||||
vch->cache = htcache_init(cache_file, cache_expiry);
|
||||
} else {
|
||||
vch->cache = NULL;
|
||||
}
|
||||
@ -324,21 +324,28 @@ int verify_work_destroy(void *handle, void *work_handle) {
|
||||
|
||||
void cache_insert(verify_container_handle_t *vch, const char *address, int result, const char *output) {
|
||||
#if ENABLE_CACHE == 1
|
||||
#ifndef CACHE_SEPARATED
|
||||
DBM *cache;
|
||||
datum data, key;
|
||||
int ret;
|
||||
#endif /* CACHE_SEPARATED */
|
||||
|
||||
int mydata_size;
|
||||
mydata_t *mydata;
|
||||
|
||||
if (1 == vch->cache_enabled) {
|
||||
syslog(LOG_DEBUG, "cache_insert: inserting %s -> %d, %s", address, result, output);
|
||||
key.dsize = strlen(address) + 1; /* one more for the terminating \0 */
|
||||
key.dptr = (char*) address;
|
||||
data.dsize = (sizeof(mydata_t) + (sizeof(char) * (strlen(output) + 1)));
|
||||
mydata = (mydata_t *) htmalloc(data.dsize);
|
||||
mydata->result = result;
|
||||
mydata->timestamp = time(NULL);
|
||||
strcpy(mydata->output, output);
|
||||
mydata_size = (sizeof(mydata_t) + (sizeof(char) * (strlen(output) + 1)));
|
||||
|
||||
#ifndef CACHE_SEPARATED
|
||||
data.dptr = (char*) mydata;
|
||||
key.dsize = strlen(address) + 1; /* one more for the terminating \0 */
|
||||
key.dptr = (char*) address;
|
||||
data.dsize = mydata_size;
|
||||
|
||||
pthread_mutex_lock(vch->cache_mutex);
|
||||
if (NULL != (cache = dbm_open(vch->cache_file, O_RDWR | O_CREAT, 0644))) {
|
||||
@ -352,6 +359,10 @@ void cache_insert(verify_container_handle_t *vch, const char *address, int resul
|
||||
dbm_close(cache);
|
||||
}
|
||||
pthread_mutex_unlock(vch->cache_mutex);
|
||||
#else /* CACHE_SEPARATED */
|
||||
htcache_insert(vch->cache, address, (const char*) mydata, mydata_size);
|
||||
#endif /* CACHE_SEPARATED */
|
||||
|
||||
|
||||
free(mydata);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user