1 #ifndef INCLUDE_cache_h__
2 #define INCLUDE_cache_h__
4 #include "git2/common.h"
8 #include "thread-utils.h"
10 #define GIT_DEFAULT_CACHE_SIZE 128
12 typedef void (*git_cached_obj_freeptr
)(void *);
28 unsigned int lru_count
;
30 git_cached_obj_freeptr free_obj
;
34 int git_cache_init(git_cache
*cache
, size_t size
, git_cached_obj_freeptr free_ptr
);
35 void git_cache_free(git_cache
*cache
);
37 void *git_cache_try_store(git_cache
*cache
, void *entry
);
38 void *git_cache_get(git_cache
*cache
, const git_oid
*oid
);
41 GIT_INLINE(int) git_cached_obj_compare(git_cached_obj
*obj
, const git_oid
*oid
)
43 return git_oid_cmp(&obj
->oid
, oid
);
46 GIT_INLINE(void) git_cached_obj_incref(git_cached_obj
*obj
)
48 git_atomic_inc(&obj
->refcount
);
51 GIT_INLINE(void) git_cached_obj_decref(git_cached_obj
*obj
, git_cached_obj_freeptr free_obj
)
53 if (git_atomic_dec(&obj
->refcount
) == 0)