Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { // FetchAndPin fetches a page from this cache. If it does not exist in the // cache, it must be loaded from a configured source. After the page was // fetched, it is pinned, meaning that it's guaranteed that the page is not // evicted. After working with the page, it must be released again, in order // for the cache to be able to free memory. If a page with the given id does // not exist, an error will be returned. FetchAndPin(id page.ID) (*page.Page, error) // Unpin tells the cache that the page with the given id is no longer // required directly, and that it can be evicted. Unpin is not a guarantee // that the page will be evicted. The cache determines, when to evict a // page. If a page with that id does not exist, this call is a no-op. Unpin(id page.ID) // Flush writes the contents of the page with the given id to the configured // source. Before a page is evicted, it is always flushed. Use this method // to tell the cache that the page must be flushed immediately. If a page // with the given id does not exist, an error will be returned. Flush(id page.ID) error io.Closer }
Cache describes a page cache that caches pages from a secondary storage.
type LRUCache ¶
type LRUCache struct {
// contains filtered or unexported fields
}
LRUCache is a simple implementation of an LRU cache.
func NewLRUCache ¶
func NewLRUCache(size int, store SecondaryStorage) *LRUCache
NewLRUCache creates a new LRU cache with the given size and secondary storage to write dirty pages to. The size is the maximum amount of pages, that can be held by this cache. If more pages than the size are requested, old pages will be evicted from the cache. If all pages are pinned (in use and not released yet), requesting a new page will fail.
func (*LRUCache) FetchAndPin ¶
FetchAndPin will return the page with the given ID. This will fail, if the page with the given ID is not in the cache, but the cache is full and all pages are pinned. After obtaining a page with this method, you MUST release it, once you are done using it, with Unpin(ID).
func (*LRUCache) Flush ¶
Flush writes the contents of the page with the given ID to secondary storage. This fails, if the page with the given ID is not in the cache anymore. Only call this if you know what you are doing. Pages will always be flushed before being evicted. If you really do need to use this, call it before unpinning the page, to guarantee that the page will not be evicted between unpinning and flushing.