housekeeper

package
v2.1.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package housekeeper manages the local cache of CheeseGull, by always keeping track of the local state of the cache and keeping it to a low amount.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CachedBeatmap

type CachedBeatmap struct {
	ID         int
	NoVideo    bool
	LastUpdate time.Time
	// contains filtered or unexported fields
}

CachedBeatmap represents a beatmap that is held in the cache of CheeseGull.

func (*CachedBeatmap) CreateFile

func (c *CachedBeatmap) CreateFile() (*os.File, error)

CreateFile creates the File of the beatmap in the filesystem, and returns it in write mode.

func (*CachedBeatmap) DownloadCompleted

func (c *CachedBeatmap) DownloadCompleted(fileSize uint64, parentHouse *House)

DownloadCompleted must be called once the beatmap has finished downloading.

func (*CachedBeatmap) File

func (c *CachedBeatmap) File() (*os.File, error)

File opens the File of the beatmap from the filesystem.

func (*CachedBeatmap) FileSize

func (c *CachedBeatmap) FileSize() uint64

FileSize returns the FileSize of c.

func (*CachedBeatmap) IsDownloaded

func (c *CachedBeatmap) IsDownloaded() bool

IsDownloaded checks whether the beatmap has been downloaded.

func (*CachedBeatmap) MustBeDownloaded

func (c *CachedBeatmap) MustBeDownloaded()

MustBeDownloaded will check whether the beatmap is downloaded. If it is not, it will wait for it to become downloaded.

func (*CachedBeatmap) SetLastRequested

func (c *CachedBeatmap) SetLastRequested(t time.Time)

SetLastRequested changes the last requested time.

func (*CachedBeatmap) String

func (c *CachedBeatmap) String() string

type House

type House struct {
	MaxSize uint64
	// contains filtered or unexported fields
}

House manages the state of the cached beatmaps in the local filesystem.

func New

func New() *House

New creates a new house, initialised with the default values.

func (*House) AcquireBeatmap

func (h *House) AcquireBeatmap(c *CachedBeatmap) (*CachedBeatmap, bool)

AcquireBeatmap attempts to add a new CachedBeatmap to the state. In order to add a new CachedBeatmap to the state, one must not already exist in the state with the same ID, NoVideo and LastUpdate. In case one is already found, this is returned, alongside with false. If LastUpdate is newer than that of the beatmap stored in the state, then the beatmap in the state's downloaded status is switched back to false and the LastUpdate is changed. true is also returned, indicating that the caller now has the burden of downloading the beatmap.

In the case the cachedbeatmap has not been stored in the state, then it is added to the state and, like the case where LastUpdated has been changed, true is returned, indicating that the caller must now download the beatmap.

If you're confused attempting to read this, let me give you an example:

A: Yo, is this beatmap cached?
B: Yes, yes it is! Here you go with the information about it. No need to do
   anything else.
   ----
A: Yo, got this beatmap updated 2 hours ago. Have you got it cached?
B: Ah, I'm afraid that I only have the version updated 10 hours ago.
   Mind downloading the updated version for me?
   ----
A: Yo, is this beatmap cached?
B: Nope, I didn't know it existed before you told me. I've recorded its
   info now, but jokes on you, you now have to actually download it.
   Chop chop!

func (*House) LoadState

func (h *House) LoadState() error

LoadState attempts to load the state from cgbin.db

func (*House) StartCleaner

func (h *House) StartCleaner()

StartCleaner starts the process that will do the necessary housekeeping every time a cleanup is scheduled with scheduleCleanup.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL