localcache

package module
v0.0.0-...-8ab0d34 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: MIT Imports: 3 Imported by: 0

README

localcache

Local file cache for storing any data e.g. configuration

Very often, a service receives a configuration from an external server using, for example, the WEB API. If you are creating a fault tolerant application e.g. SCADA, your application shall work regardless of the current state of the SCADA WEB API configuration server. The main idea of this library is to save the configuration to a local cache file and restore the configuration from the file in case the WEB API configuration server fails.

How to use

cache := localcache.New(cachePath)

if loadFromCacheOnly {
	return cache.Load()
}
  
 profileData, err = api.GetProfileFromWebApi()
 if err != nil {
 	return cache.Load()
}
   
cache.Save(profileData)
return profileData

Before saving, this library checks the checksum of the data and the saved file, and saves data only if the checksums differ.

Testing

To run tests run:

go test -v

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LocalCache

type LocalCache struct {
	ChecksumIEEE uint32
	PathToCache  string
	IsChanged    bool
}

func New

func New(pathToCache string) *LocalCache

func (*LocalCache) Load

func (s *LocalCache) Load() ([]byte, error)

Load from local cache

func (*LocalCache) Save

func (s *LocalCache) Save(profileData []byte) error

Save configuration to local cache file

Jump to

Keyboard shortcuts

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