static MmsValue* searchCacheForValue(MmsValueCache self, char* itemId, char* parentId) { MmsValueCacheEntry* cacheEntry; MmsValue* value = NULL; cacheEntry = (MmsValueCacheEntry*) Map_getEntry(self->map, parentId); if (cacheEntry == NULL) { char* parentItemId = getParentSubString(parentId); if (parentItemId != NULL) { value = searchCacheForValue(self, itemId, parentItemId); } } else { char* childId = getChildSubString(itemId, parentId); MmsVariableSpecification* typeSpec = MmsDomain_getNamedVariable(self->domain, parentId); value = MmsVariableSpecification_getChildValue(typeSpec, cacheEntry->value, childId); } return value; }
MmsValue* MmsValueCache_lookupValue(MmsValueCache self, char* itemId) { // get value for first matching key substring! // Then iterate the value for the exact value. MmsValue* value = NULL; MmsValueCacheEntry* cacheEntry; cacheEntry = (MmsValueCacheEntry*) Map_getEntry(self->map, itemId); if (cacheEntry == NULL) { char* itemIdCopy = copyString(itemId); char* parentItemId = getParentSubString(itemIdCopy); if (parentItemId != NULL) { value = searchCacheForValue(self, itemId, parentItemId); } GLOBAL_FREEMEM(itemIdCopy); } if (cacheEntry != NULL) return cacheEntry->value; else return value; }
void MmsServer_insertIntoCache(MmsServer self, MmsDomain* domain, char* itemId, MmsValue* value) { MmsValueCache cache = Map_getEntry(self->valueCaches, domain); if (cache != NULL) { MmsValueCache_insertValue(cache, itemId, value); } }
MmsValue* MmsServer_getValueFromCache(MmsServer self, MmsDomain* domain, char* itemId) { MmsValueCache cache = Map_getEntry(self->valueCaches, domain); if (cache != NULL) { return MmsValueCache_lookupValue(cache, itemId); } return NULL; }