TILT-caching- part 17
If you want to read about, see https://docs.microsoft.com/en-us/azure/architecture/patterns/cache-aside
So , the public TILTS must be cached. Also, when a user makes a new TILT, the cache should be destroyed
The code for Memory Cache is very simple:
- Add to services
builder.Services.AddMemoryCache();
- Add an MemoryCache cache to the constructor
public MyTilts(IMemoryCache cache,
- add caching to the function
if (cache.TryGetValue<TILT_Note_Table[]>(urlPart, out var result)) { return result; } //code to retrieve cache.Set(urlPart, ret,DateTimeOffset.Now.AddMinutes(10)); return ret;
- add destroy cache
await insert.InsertTILT_Note(noteOrig); note.CopyFrom(noteOrig); cache.Remove(url);
- Modify tests to see this feature
Leave a Reply