cache

command
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2022 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Example: Key/Value Cache

This example demonstrates a Key column type that allows you to perform O(1) lookups over that. This can be used in the case where you do not have a specific offset for the entry.

// Cache represents a key-value store
type Cache struct {
	store *column.Collection
}

// New creates a new key-value cache
func New() *Cache {
	db := column.NewCollection()
	db.CreateColumn("key", column.ForKey())
	db.CreateColumn("val", column.ForString())

	return &Cache{
		store: db,
	}
}

// Get attempts to retrieve a value for a key
func (c *Cache) Get(key string) (value string, found bool) {
	c.store.QueryKey(key, func(r column.Row) error {
		value, found = r.String("val")
		return nil
	})
	return
}

// Set updates or inserts a new value
func (c *Cache) Set(key, value string) {
	if err := c.store.QueryKey(key, func(r column.Row) error {
		r.SetString("val", value)
		return nil
	}); err != nil {
		panic(err)
	}
}

Some Results

running insert of 50000 rows...
-> inserted 10000 rows
-> inserted 20000 rows
-> inserted 30000 rows
-> inserted 40000 rows
-> inserted 50000 rows
-> insert took 80.2478ms

running query of user_11255...
Hi, User 11255 true
-> query took 1.271µs

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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