Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a simple in memory cache that stores data in a map in memory. The cache is not persistent, so it will be lost when the application is restarted.
For the sake of speed and simplicity, try to store only necessary data in the cache to reduce the memory footprint and improve performance.
func New ¶
Use this function to create a new cache
You can opt out of specifying the reset time and by default it will be set to 1 second Reset time is the time between each check for expired data
func (*Cache) Exists ¶
checks if the data exists in the cache using the key
If you call this method and immediately afterwards call the Get method within the window of time that the data in the cache is set to expire, sometimes exists will return true but Get will return nil
To avoid this, you can call the Get method directly and check if the value returned is nil or not
func (*Cache) Get ¶
Gets the data from the cache using the key. If the data is not found, it returns nil
func (*Cache) Set ¶
Sets a new item to the cache specifying the key and data to store
You can opt out of specifying the time to live (ttl) and by default the cache will use the value specified when creating the cache using the New function
This will also start the cache if there was no items in the cache before.