Created
October 11, 2018 12:28
-
-
Save Regenhardt/20552120868e39dfae292befb80e3eb9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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