cache.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. * SPDX-License-Identifier: Apache-2.0.
  4. */
  5. #include <aws/common/cache.h>
  6. void aws_cache_destroy(struct aws_cache *cache) {
  7. AWS_PRECONDITION(cache);
  8. cache->vtable->destroy(cache);
  9. }
  10. int aws_cache_find(struct aws_cache *cache, const void *key, void **p_value) {
  11. AWS_PRECONDITION(cache);
  12. return cache->vtable->find(cache, key, p_value);
  13. }
  14. int aws_cache_put(struct aws_cache *cache, const void *key, void *p_value) {
  15. AWS_PRECONDITION(cache);
  16. return cache->vtable->put(cache, key, p_value);
  17. }
  18. int aws_cache_remove(struct aws_cache *cache, const void *key) {
  19. AWS_PRECONDITION(cache);
  20. return cache->vtable->remove(cache, key);
  21. }
  22. void aws_cache_clear(struct aws_cache *cache) {
  23. AWS_PRECONDITION(cache);
  24. cache->vtable->clear(cache);
  25. }
  26. size_t aws_cache_get_element_count(const struct aws_cache *cache) {
  27. AWS_PRECONDITION(cache);
  28. return cache->vtable->get_element_count(cache);
  29. }
  30. void aws_cache_base_default_destroy(struct aws_cache *cache) {
  31. aws_linked_hash_table_clean_up(&cache->table);
  32. aws_mem_release(cache->allocator, cache);
  33. }
  34. int aws_cache_base_default_find(struct aws_cache *cache, const void *key, void **p_value) {
  35. return (aws_linked_hash_table_find(&cache->table, key, p_value));
  36. }
  37. int aws_cache_base_default_remove(struct aws_cache *cache, const void *key) {
  38. /* allocated cache memory and the linked list entry will be removed in the
  39. * callback. */
  40. return aws_linked_hash_table_remove(&cache->table, key);
  41. }
  42. void aws_cache_base_default_clear(struct aws_cache *cache) {
  43. /* clearing the table will remove all elements. That will also deallocate
  44. * any cache entries we currently have. */
  45. aws_linked_hash_table_clear(&cache->table);
  46. }
  47. size_t aws_cache_base_default_get_element_count(const struct aws_cache *cache) {
  48. return aws_linked_hash_table_get_element_count(&cache->table);
  49. }