#[unsafe(no_mangle)]pub extern "C" fn dmsc_memory_cache_new() -> *mut CDMSCMemoryCacheExpand description
Creates a new DMSCMemoryCache instance.
Initializes an empty in-memory cache with default configuration. The cache starts empty and grows as entries are added. Memory usage is managed automatically through eviction policies.
§Returns
Pointer to newly allocated DMSCMemoryCache on success, or NULL if memory allocation fails. The returned pointer must be freed using dmsc_memory_cache_free().
§Initial State
A newly created memory cache:
- Contains zero entries
- Has no memory usage
- Uses default LRU eviction
- No maximum capacity enforcement until configured
§Usage Pattern
DMSCMemoryCache* cache = dmsc_memory_cache_new();
if (cache == NULL) {
// Handle allocation failure
return ERROR_MEMORY_ALLOCATION;
}
// Configure capacity if needed
dmsc_memory_cache_set_max_size(cache, 100000);
// Use cache operations
dmsc_memory_cache_set(cache, "key", "value", 5);
char* value = dmsc_memory_cache_get(cache, "key", NULL);
// Cleanup
dmsc_memory_cache_free(cache);§Performance Considerations
For optimal performance:
- Configure capacity before heavy usage
- Batch similar operations together
- Use appropriate serialization format
- Monitor cache hit rate for tuning