cache

package
v0.0.0-...-cbb00c2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 16 Imported by: 6

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

This section is empty.

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 items.EncryptedItems, close bool) error

SaveEncryptedItems converts to cache items and persists to db.

func SaveItems

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

SaveItems saves Items to the provided database.

func SaveNotes

func SaveNotes(s *Session, db *storm.DB, items items.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 items.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 items.EncryptedItems, clean bool) (pitems Items)

func (Items) ToItems

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

func (Items) UUIDs

func (i Items) UUIDs() []string

func (Items) Validate

func (i Items) Validate() error

func (Items) ValidateSaved

func (i Items) ValidateSaved() error

type Session

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

func GetSession

func GetSession(httpClient *retryablehttp.Client, 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 *auth.SignInResponseDataSession, 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) Gosn

func (s Session) Gosn() session.Session

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