static void cacheex_del_hitcache(struct s_client *cl, ECM_REQUEST *er) { HIT_KEY search; CACHE_HIT *result; memset(&search, 0, sizeof(HIT_KEY)); search.caid = er->caid; search.prid = er->prid; search.srvid = er->srvid; if(cl && cl->grp) { result = find_hash_table(&ht_hitcache, &search, sizeof(HIT_KEY), &cacheex_compare_hitkey); while(result) { result->grp &= ~cl->grp; result->grp_last_max_hitcache_time &= ~cl->grp; result = find_hash_table(&ht_hitcache, &search, sizeof(HIT_KEY), &cacheex_compare_hitkey); } } SAFE_RWLOCK_WRLOCK(&hitcache_lock); search_remove_elem_hash_table(&ht_hitcache, &search, sizeof(HIT_KEY), &cacheex_compare_hitkey); SAFE_RWLOCK_UNLOCK(&hitcache_lock); }
void cacheex_cleanup_hitcache(bool force) { CACHE_HIT *cachehit; node *i,*i_next; struct timeb now; int64_t gone; int32_t timeout = (cfg.max_hitcache_time + (cfg.max_hitcache_time / 2))*1000; //1,5 SAFE_RWLOCK_WRLOCK(&hitcache_lock); i = get_first_node_list(&ll_hitcache); while (i) { i_next = i->next; cachehit = get_data_from_node(i); if(!cachehit) { i = i_next; continue; } cs_ftime(&now); gone = comp_timeb(&now, &cachehit->time); if(force || gone>timeout) { remove_elem_list(&ll_hitcache, &cachehit->ll_node); remove_elem_hash_table(&ht_hitcache, &cachehit->ht_node); NULLFREE(cachehit); } i = i_next; } SAFE_RWLOCK_UNLOCK(&hitcache_lock); }
static void cacheex_del_hitcache(ECM_REQUEST *er) { HIT_KEY search; memset(&search, 0, sizeof(HIT_KEY)); search.caid = er->caid; search.prid = er->prid; search.srvid = er->srvid; SAFE_RWLOCK_WRLOCK(&hitcache_lock); search_remove_elem_hash_table(&ht_hitcache, &search, sizeof(HIT_KEY), &cacheex_compare_hitkey); SAFE_RWLOCK_UNLOCK(&hitcache_lock); }
static void cacheex_add_hitcache(struct s_client *cl, ECM_REQUEST *er) { if (!cfg.max_hitcache_time) // we don't want check/save hitcache return; if (!cfg.cacheex_wait_timetab.cevnum) return; uint32_t cacheex_wait_time = get_cacheex_wait_time(er,NULL); if (!cacheex_wait_time) return; CACHE_HIT *result; HIT_KEY search; memset(&search, 0, sizeof(HIT_KEY)); search.caid = er->caid; search.prid = er->prid; search.srvid = er->srvid; SAFE_RWLOCK_WRLOCK(&hitcache_lock); result = find_hash_table(&ht_hitcache, &search, sizeof(HIT_KEY), &cacheex_compare_hitkey); if(!result) // not found, add it! { if(cs_malloc(&result, sizeof(CACHE_HIT))) { memset(result, 0, sizeof(CACHE_HIT)); result->key.caid = er->caid; result->key.prid = er->prid; result->key.srvid = er->srvid; cs_ftime(&result->max_hitcache_time); add_hash_table(&ht_hitcache, &result->ht_node, &ll_hitcache, &result->ll_node, result, &result->key, sizeof(HIT_KEY)); } } if(result) { if(cl) { result->grp |= cl->grp; result->grp_last_max_hitcache_time |= cl->grp; } cs_ftime(&result->time); //always update time; } SAFE_RWLOCK_UNLOCK(&hitcache_lock); }