cache

package
v0.0.0-...-faf8740 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 13 Imported by: 0

README

about

####Note: This is an early release with significant changes. Please take a backup before using with any real data and report any issues you find.

This package is used to persist encrypted SN items to a local key-value store and then only sync deltas on subsequent calls.

usage

under construction

sign in

sio, _ := gosn.SignIn(gosn.SignInInput{
    Email:    "user@example.com",
    Password: "topsecret",
})

get cache session

cs, _ := cache.ImportSession(&sio.Session, "")

sync items to database

cso, _ := cache.Sync(cache.SyncInput{
    Session: cs,
})

retrieve items

var cItems []cache.Item
_ = cso.DB.All(&cItems)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HiWhite = color.New(color.FgHiWhite).SprintFunc()

Functions

func CleanCacheItems

func CleanCacheItems(db *storm.DB, items Items, close bool) error

CleanCacheItems marks Cache Items as clean (Dirty = false) and resets dirtied date to the provided database.

func DeleteCacheItems

func DeleteCacheItems(db *storm.DB, items Items, close bool) error

DeleteCacheItems saves Cache Items to the provided database.

func GenCacheDBPath

func GenCacheDBPath(session Session, dir, appName string) (string, error)

GenCacheDBPath generates a path to a database file to be used as a cache of encrypted items The filename is a SHA2 hash of a concatenation of the following in order to be both unique and avoid concurrent usage: - part of the session authentication key (so that caches are unique to a user) - the server URL (so that caches are server specific) - the requesting application name (so that caches are application specific).

func SaveCacheItems

func SaveCacheItems(db *storm.DB, items Items, close bool) error

SaveCacheItems saves Cache Items to the provided database.

func SaveEncryptedItems

func SaveEncryptedItems(db *storm.DB, items gosn.EncryptedItems, close bool) error

SaveEncryptedItems converts to cache items and persists to db.

func SaveItems

func SaveItems(s *Session, db *storm.DB, items gosn.Items, close bool) error

SaveItems saves Items to the provided database.

func SaveNotes

func SaveNotes(s *Session, db *storm.DB, items gosn.Notes, close bool) error

SaveNotes encrypts, converts to cache items, and then persists to db.

func SaveTags

func SaveTags(db *storm.DB, s *Session, items gosn.Tags, close bool) error

SaveTags encrypts, converts to cache items, and then persists to db.

Types

type CleanInput

type CleanInput struct {
	*Session
	Close                 bool
	UnreferencedItemsKeys bool
}

type Item

type Item struct {
	UUID               string `storm:"id,unique"`
	Content            string
	ContentType        string `storm:"index"`
	ItemsKeyID         *string
	EncItemKey         string
	Deleted            bool
	CreatedAt          string
	UpdatedAt          string
	CreatedAtTimestamp int64
	UpdatedAtTimestamp int64
	DuplicateOf        *string
	Dirty              bool
	DirtiedDate        time.Time
}

type Items

type Items []Item

func ToCacheItems

func ToCacheItems(items gosn.EncryptedItems, clean bool) (pitems Items)

func (Items) ToItems

func (pi Items) ToItems(s *Session) (items gosn.Items, err error)

func (Items) Validate

func (i Items) Validate() error

type Session

type Session struct {
	*gosn.Session
	CacheDB     *storm.DB
	CacheDBPath string
}

func GetSession

func GetSession(loadSession bool, sessionKey, server string, debug bool) (s Session, email string, err error)

GetSession returns a cache session that encapsulates a gosn-v2 session with additional configuration for managing a local cache database.

func ImportSession

func ImportSession(gs *gosn.Session, path string) (s *Session, err error)

ImportSession creates a new Session from an existing gosn.Session instance with the option of specifying a path for the db other than the home folder.

func (*Session) Export

func (s *Session) Export(path string) error

func (Session) Gosn

func (s Session) Gosn() gosn.Session

func (*Session) Import

func (s *Session) Import(path string, persist bool) error

Import reads a json export file into SN and then syncs with the db.

func (*Session) RemoveDB

func (s *Session) RemoveDB()

type SyncInput

type SyncInput struct {
	*Session
	Close bool
}

type SyncOutput

type SyncOutput struct {
	DB *storm.DB
}

func Sync

func Sync(si SyncInput) (so SyncOutput, err error)

Sync will push any dirty items to SN and make database cache consistent with SN.

type SyncToken

type SyncToken struct {
	SyncToken string `storm:"id,unique"`
}

Jump to

Keyboard shortcuts

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