Skip to content

Instantly share code, notes, and snippets.

@Regenhardt
Created October 11, 2018 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Regenhardt/20552120868e39dfae292befb80e3eb9 to your computer and use it in GitHub Desktop.
Save Regenhardt/20552120868e39dfae292befb80e3eb9 to your computer and use it in GitHub Desktop.
/// <summary>
/// Caches objects.
/// </summary>
public class Cache<T>
{
private List<T> cache;
/// <summary>
/// Initializes a new <see cref="Cache{T}"/>:
/// </summary>
public Cache()
{
cache = new List<T>();
}
/// <summary>
/// Adds a new message to the cache.
/// </summary>
/// <param name="message">Message to add to the cache.</param>
public void Add(T message)
{
cache.Add(message);
}
/// <summary>
/// Removes and returns the currently cached objects.
/// Currently not thread safe.
/// </summary>
/// <returns></returns>
public List<T> GetCachedMessages()
{
var oldList = cache;
cache = new List<T>();
return oldList;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment