/// <summary> /// Initialize the cache with the given list of objects. /// </summary> /// <param name="jsonObjects">The objects to initialize the cache with.</param> void Initialize(IEnumerable <JsonObject> jsonObjects) { foreach (var jsonObject in jsonObjects) { _objectCache[JsonApiEntityKey.Create(jsonObject)] = jsonObject; } }
/// <summary> /// Attempts to get the entity from the cache. /// </summary> /// <param name="cache">The cache to perform the operation on.</param> /// <param name="key">The JSON API entity key to return the value for.</param> /// <param name="value">The value that was associated with the given key.</param> /// <returns>true if the an entity was found for the key, false if not.</returns> internal static bool TryGetValue(this IJsonApiEntityCache cache, JsonApiEntityKey key, out object value) { if (cache == null) { throw new ArgumentNullException(nameof(cache)); } return(cache.TryGetValue(key.Type, key.Id, out value)); }
/// <summary> /// Attempt to return the JSON object for the given JSON Entity Key. /// </summary> /// <param name="jsonEntityKey">The JSON entity key to return the JSON object for.</param> /// <param name="jsonObject">The JSON object that was assigned to the given key.</param> /// <returns>true if the JSON object was found for the entity key, false if not.</returns> internal bool TryGetObject(JsonApiEntityKey jsonEntityKey, out JsonObject jsonObject) { return(_objectCache.TryGetValue(jsonEntityKey, out jsonObject)); }