Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDiskFull = errors.New("there was no space left on the device")
var ErrExists = errors.New("key already exists")
var ErrInvalidPath = errors.New("path supplied is invalid")
var ErrNotExists = errors.New("key does not exist")
Functions ¶
This section is empty.
Types ¶
type Cache ¶
func Default ¶
func Default() *Cache
Creates default Cheapcash instance which defaults the corresponding cache path to /tmp/cheapcash.
The caveat of using this one is this will be most likely only compatible with UNIX-like filesystem. Windows devices will most likely happen to have an error of the invalid path.
This returns a Cheapcash instance, which method ('Append', 'Exists', 'Write', 'Read') you can do by just specifying the key, without supplying the full path of the cached file.
func New ¶
Creates a new Cheapcash instance with the given path from the argument provided.
If path is empty (or an empty string), it will panic with ErrInvalidPath error.
The path provided might have '/' as the ending, so these are valid and will return the same path:
New("/tmp/box") New("/tmp/box/")
func (*Cache) Append ¶
Directly append a value into an existing key. If a key doesn't exists, it will return an error with a type of ErrNotExists.
c := cheapcash.Default() err := c.Append("users", []byte("Someone\n")) if err != nil { if errors.Is(err, cheapcash.ErrNotExists) { // Handle if file does not exists! } // Handle any other errors }
func (*Cache) Delete ¶
Delete a key from the cache directory. And of course would return an error of ErrNotExists if the key doesn't exists.
c := cheapcash.Default() err := c.Write("users", []byte("Someone\n")) // Handle error here err = c.Delete("users") // Handle error here
func (*Cache) Exists ¶
Check whether or not a key exists. Returns true if the key exists, false otherwise.
WARNING: You should provide your c.Path value yourself.
check, err := cache.Exists("something.txt") // will search in ./something.txt check, err = cache.Exists(c.Path + "something.txt") // will search relative to c.Path value
func (*Cache) Read ¶
Read the value of a given key. Will return an error of ErrNotExists if the given key does not exists.
c := cheapcash.Default() res, err := c.Read("users") if err != nil { // handle your error here! } log.Println(string(res))
func (*Cache) Rename ¶
Rename a key. It's that simple. The contents of the cache stays the same, but the key is renamed.
It will return 2 different error in case of:
1. If the old key (first argument parameter) doesn't exists, it will return an error of ErrNotExists
2. If the new key (second argument parameter) already exists, it will return an error of ErrExists