storage

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2015 License: GPL-3.0 Imports: 9 Imported by: 3

README

Storage Modules

The logic for storing cached files in nedomi is highly modular. At the moment we have a built in storage on disk. But you can have as many and as different as you want. They are all subpackages in the storage/ directory.

Contents

Anatomy of a Storage Module

It is a subpackage in the storage/ directory. It follows the follwing rules:

  • Has a func New(cfg config.CacheZone, ca types.CacheAlgorithm, logger types.Logger) *T function.

  • T must conform to the Storage interface which is defined in storage/interface.go

How to Write Your Own Module?

You can add your module by creating a directory with a subpackage in the storage/ directory.

  • Go into the storage/ directory with $ cd .../nedomi/storage
  • Create a directory for your module. The name of the directory will be name of the module. Lets say you want to create a redis module. mkdir redis
  • Write your implementation of Storage in this directory as package redis
  • In the main nedomi directory run cd .../nedomi && go generate ./...

Removing a Module

Lets say you want to remove the redis module.

  • cd .../nedomi/cache
  • rm -rf redis
  • cd .. && go generate ./...

You can remove any storage module as well. Including the built in modules. Just make sure there is at least one left. Otherwise you wouldn't be able to start the server after compiling. The source will compile happily without any modules left, though.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetExpirationHandler

func GetExpirationHandler(cz *types.CacheZone, logger types.Logger, id *types.ObjectID) func()

GetExpirationHandler returns a potentially long-lived callback that removes the specified object from the storage.

func New

func New(cfg *config.CacheZone, log types.Logger) (types.Storage, error)

New returns a new Storage ready for use. The st argument sets which type of storage will be returned.

Types

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}

Scheduler efficiently manages and executes callbacks at specified times.

func NewScheduler

func NewScheduler() (em *Scheduler)

NewScheduler initializes and returns a newly created Scheduler instance.

func (*Scheduler) AddEvent

func (em *Scheduler) AddEvent(key types.ObjectIDHash, callback func(), expire time.Duration)

AddEvent schedules the passed callback to be executed at the supplied time.

func (*Scheduler) Cleanup

func (em *Scheduler) Cleanup()

Cleanup removes all scheduled events

func (*Scheduler) Contains

func (em *Scheduler) Contains(key types.ObjectIDHash) bool

Contains checks whether an event with the supplied key is scheduled.

func (*Scheduler) Destroy

func (em *Scheduler) Destroy()

Destroy stops and destroys the scheduler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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