mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-30 18:08:44 +00:00
Clear the cache when there are too many items to expire
This commit is contained in:
parent
e16e268457
commit
e183e375b8
21
src/cache.c
21
src/cache.c
@ -63,14 +63,33 @@ void git_cache_free(git_cache *cache)
|
|||||||
git_mutex_free(&cache->lock);
|
git_mutex_free(&cache->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void git_cache_clear(git_cache *cache)
|
||||||
|
{
|
||||||
|
git_cached_obj *evict = NULL;
|
||||||
|
|
||||||
|
if (git_mutex_lock(&cache->lock) < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
kh_foreach_value(cache->map, evict, {
|
||||||
|
git_cached_obj_decref(evict);
|
||||||
|
});
|
||||||
|
|
||||||
|
kh_clear(oid, cache->map);
|
||||||
|
cache->used_memory = 0;
|
||||||
|
|
||||||
|
git_mutex_unlock(&cache->lock);
|
||||||
|
}
|
||||||
|
|
||||||
/* Call with lock, yo */
|
/* Call with lock, yo */
|
||||||
static void cache_evict_entries(git_cache *cache, size_t evict_count)
|
static void cache_evict_entries(git_cache *cache, size_t evict_count)
|
||||||
{
|
{
|
||||||
uint32_t seed = rand();
|
uint32_t seed = rand();
|
||||||
|
|
||||||
/* do not infinite loop if there's not enough entries to evict */
|
/* do not infinite loop if there's not enough entries to evict */
|
||||||
if (evict_count > kh_size(cache->map))
|
if (evict_count > kh_size(cache->map)) {
|
||||||
|
git_cache_clear(cache);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while (evict_count > 0) {
|
while (evict_count > 0) {
|
||||||
khiter_t pos = seed++ % kh_end(cache->map);
|
khiter_t pos = seed++ % kh_end(cache->map);
|
||||||
|
Loading…
Reference in New Issue
Block a user