web api startup add imemory cache object
C#
#region cached data
private IMemoryCache _cache;
public HomeController(IMemoryCache memoryCache)
{
_cache = memoryCache;
}
public static class CacheKeys
{
public static string Entry { get { return "_Entry"; } }
public static string CallbackEntry { get { return "_Callback"; } }
public static string CallbackMessage { get { return "_CallbackMessage"; } }
public static string Parent { get { return "_Parent"; } }
public static string Child { get { return "_Child"; } }
public static string DependentMessage { get { return "_DependentMessage"; } }
public static string DependentCTS { get { return "_DependentCTS"; } }
public static string Ticks { get { return "_Ticks"; } }
public static string CancelMsg { get { return "_CancelMsg"; } }
public static string CancelTokenSource { get { return "_CancelTokenSource"; } }
}
public IActionResult CacheTryGetValueSet()
{
DateTime cacheEntry;
// Look for cache key.
if (!_cache.TryGetValue(CacheKeys.Entry, out cacheEntry))
{
// Key not in cache, so get data.
cacheEntry = DateTime.Now;
// Set cache options.
var cacheEntryOptions = new MemoryCacheEntryOptions()
// Keep in cache for this time, reset time if accessed.
.SetSlidingExpiration(TimeSpan.FromSeconds(3));
// Save data in cache.
_cache.Set(CacheKeys.Entry, cacheEntry, cacheEntryOptions);
}
return View("Cache", cacheEntry);
}
#endregion
Also in C#:
- Title
- c# loop through list
- Category
- C#
- Title
- how to mock abstract httpcontext using moq .net core
- Category
- C#
- Title
- Exception thrown: 'System.FormatException' in mscorlib.dll dates
- Category
- C#
- Title
- progress openedge odbc connection string c#
- Category
- C#
- Title
- c# regex to find number between parenthesis
- Category
- C#
- Title
- if get key down unity
- Category
- C#
- Title
- replace all ponctuation characters c#
- Category
- C#
- Title
- .net identity seed users and roles
- Category
- C#
- Title
- abstract class c#
- Category
- C#
- Title
- convert array to list Unity C#
- Category
- C#
- Title
- unity ui change sprite
- Category
- C#
- Title
- unity how to get y value
- Category
- C#
- Title
- what is a return statement C#
- Category
- C#
- Title
- c# resize image keep aspect ratio
- Category
- C#
- Title
- c# replace foreach with lambda
- Category
- C#
- Title
- c# iterate over string
- Category
- C#
- Title
- c# how to add newline on text box
- Category
- C#
- Title
- c# empty char
- Category
- C#
- Title
- c# round number
- Category
- C#
- Title
- How to get number of months between 2 dates c#
- Category
- C#
- Title
- get string character by index c#
- Category
- C#
- Title
- c# get country code
- Category
- C#
- Title
- c# convert to nullable datetime
- Category
- C#
- Title
- c# webcam
- Category
- C#
- Title
- or in unity c#
- Category
- C#
- Title
- c# property get set
- Category
- C#
- Title
- how to change an int value c#
- Category
- C#
- Title
- no entity framework provider found for the ado.net provider with invariant name
- Category
- C#
- Title
- using serial port in c#
- Category
- C#
- Title
- text variable type unity
- Category
- C#
- Title
- c# retrieve files in folder
- Category
- C#
- Title
- c# index in select
- Category
- C#
- Title
- c# convert byte to char
- Category
- C#
- Title
- c# making a folder
- Category
- C#
- Title
- using in c#
- Category
- C#
- Title
- how to draw a dot in c#
- Category
- C#
- Title
- how to clear console through script unity
- Category
- C#
- Title
- c# typeof
- Category
- C#
- Title
- date time heutiges datum
- Category
- C#
- Title
- c# access session in class
- Category
- C#
- Title
- C# events
- Category
- C#
- Title
- instantiate object in circle
- Category
- C#
- Title
- rotatearound unity
- Category
- C#
- Title
- download and run exe c# 1 button
- Category
- C#
- Title
- transform object according to its parent unity
- Category
- C#
- Title
- C# type cast float to string
- Category
- C#
- Title
- windows forms iterate through all controls
- Category
- C#
- Title
- c# thread sleep
- Category
- C#
- Title
- c# query string builder
- Category
- C#
- Title
- c# datafield change cell background color
- Category
- C#
- Title
- epplus excel vb.net
- Category
- C#
- Title
- c# check if string is only letters and numbers
- Category
- C#
- Title
- c# arraylist
- Category
- C#
- Title
- c# print to console
- Category
- C#
- Title
- onmouseclick unity
- Category
- C#
- Title
- list of vectors c#
- Category
- C#
- Title
- print gridcontrol devexpress
- Category
- C#
- Title
- convert string to decimal c#
- Category
- C#
- Title
- C# webclient submit form
- Category
- C#
- Title
- blazor wasm routable page in separate project
- Category
- C#
- Title
- gfortran: declare an array
- Category
- C#
- Title
- null coalescing operator c#
- Category
- C#
- Title
- unity input get axis
- Category
- C#
- Title
- make a list c#
- Category
- C#
- Title
- c# tostring mmm dd yyyy
- Category
- C#
- Title
- c# substring from index to end
- Category
- C#
- Title
- c# md5 int
- Category
- C#
- Title
- validating file upload asp.net core mvc
- Category
- C#
- Title
- c# mixed multidimensional array
- Category
- C#
- Title
- as c#
- Category
- C#
- Title
- unity rigidbody constraints
- Category
- C#
- Title
- how to remove space between string in c#
- Category
- C#
- Title
- how to add to an array c#
- Category
- C#
- Title
- hot to move pobject unity
- Category
- C#
- Title
- c# arraylist contains
- Category
- C#
- Title
- unity particle system color
- Category
- C#
- Title
- c# to vb.net
- Category
- C#
- Title
- parsing object from text file c#
- Category
- C#
- Title
- csharp attributes as generics constraints
- Category
- C#
- Title
- parse strings into words C#
- Category
- C#
- Title
- modal dismiss
- Category
- C#
- Title
- usermanager find based on role
- Category
- C#
- Title
- unity c# change color of gameobject
- Category
- C#
- Title
- razor: show editable list
- Category
- C#
- Title
- what function is called just before the a script is ended c#
- Category
- C#
- Title
- background color with opacity
- Category
- C#
- Title
- dto and automapper
- Category
- C#
- Title
- How can you learn C# on your own
- Category
- C#
- Title
- letter at index of string c#
- Category
- C#
- Title
- c# reverse array
- Category
- C#
- Title
- unity change tag in script
- Category
- C#
- Title
- unity clamp rotation
- Category
- C#
- Title
- countdown script in unity
- Category
- C#
- Title
- c# add object to array
- Category
- C#
- Title
- c# how to sort a list
- Category
- C#
- Title
- c# main method
- Category
- C#
- Title
- c# convert column name to number
- Category
- C#
- Title
- c# windows application get current path
- Category
- C#
- Title
- c# how to use inovke
- Category
- C#
- Title
- c sharp substring
- Category
- C#