🦴 update skeleton

This commit is contained in:
Fenny
2020-10-31 11:58:00 +01:00
parent ef04d509b9
commit 0692b9048e
10 changed files with 117 additions and 23 deletions

View File

@@ -1,13 +1,21 @@
package memcached
import "time"
// Config defines the config for storage.
type Config struct {
GCInterval time.Duration
}
// ConfigDefault is the default config
var ConfigDefault = Config{}
var ConfigDefault = Config{
GCInterval: 10 * time.Second,
}
// Helper function to set default values
func configDefault(cfg Config) Config {
if int(cfg.GCInterval) == 0 {
cfg.GCInterval = ConfigDefault.GCInterval
}
return cfg
}

View File

@@ -1,11 +1,10 @@
package memcached
import (
"time"
)
import "time"
// Storage interface that is implemented by storage providers
type Storage struct {
gcInterval time.Duration
}
// New creates a new storage
@@ -18,10 +17,15 @@ func New(config ...Config) *Storage {
cfg = configDefault(config[0])
}
// TODO
_ = cfg
// Create storage
store := &Storage{
gcInterval: cfg.GCInterval,
}
return &Storage{}
// Start garbage collector
go store.gc()
return store
}
// Get value by key
@@ -43,3 +47,12 @@ func (s *Storage) Delete(key string) error {
func (s *Storage) Clear() error {
return nil
}
// Garbage collector to delete expired keys
func (s *Storage) gc() {
tick := time.NewTicker(s.gcInterval)
for {
<-tick.C
// clean entries
}
}

View File

@@ -2,7 +2,7 @@ package memory
import "time"
// Config defines the config for memory storage.
// Config defines the config for storage.
type Config struct {
GCInterval time.Duration
}

View File

@@ -33,7 +33,7 @@ func New(config ...Config) *Storage {
gcInterval: cfg.GCInterval,
}
// start garbage collector
// Start garbage collector
go store.gc()
return store

View File

@@ -1,13 +1,21 @@
package mysql
import "time"
// Config defines the config for storage.
type Config struct {
GCInterval time.Duration
}
// ConfigDefault is the default config
var ConfigDefault = Config{}
var ConfigDefault = Config{
GCInterval: 10 * time.Second,
}
// Helper function to set default values
func configDefault(cfg Config) Config {
if int(cfg.GCInterval) == 0 {
cfg.GCInterval = ConfigDefault.GCInterval
}
return cfg
}

View File

@@ -1,9 +1,12 @@
package mysql
import "time"
import (
"time"
)
// Storage interface that is implemented by storage providers
type Storage struct {
gcInterval time.Duration
}
// New creates a new storage
@@ -16,10 +19,15 @@ func New(config ...Config) *Storage {
cfg = configDefault(config[0])
}
// TODO
_ = cfg
// Create storage
store := &Storage{
gcInterval: cfg.GCInterval,
}
return &Storage{}
// Start garbage collector
go store.gc()
return store
}
// Get value by key
@@ -41,3 +49,12 @@ func (s *Storage) Delete(key string) error {
func (s *Storage) Clear() error {
return nil
}
// Garbage collector to delete expired keys
func (s *Storage) gc() {
tick := time.NewTicker(s.gcInterval)
for {
<-tick.C
// clean entries
}
}

View File

@@ -1,13 +1,21 @@
package postgres
import "time"
// Config defines the config for storage.
type Config struct {
GCInterval time.Duration
}
// ConfigDefault is the default config
var ConfigDefault = Config{}
var ConfigDefault = Config{
GCInterval: 10 * time.Second,
}
// Helper function to set default values
func configDefault(cfg Config) Config {
if int(cfg.GCInterval) == 0 {
cfg.GCInterval = ConfigDefault.GCInterval
}
return cfg
}

View File

@@ -1,9 +1,12 @@
package postgres
import "time"
import (
"time"
)
// Storage interface that is implemented by storage providers
type Storage struct {
gcInterval time.Duration
}
// New creates a new storage
@@ -16,10 +19,15 @@ func New(config ...Config) *Storage {
cfg = configDefault(config[0])
}
// TODO
_ = cfg
// Create storage
store := &Storage{
gcInterval: cfg.GCInterval,
}
return &Storage{}
// Start garbage collector
go store.gc()
return store
}
// Get value by key
@@ -41,3 +49,12 @@ func (s *Storage) Delete(key string) error {
func (s *Storage) Clear() error {
return nil
}
// Garbage collector to delete expired keys
func (s *Storage) gc() {
tick := time.NewTicker(s.gcInterval)
for {
<-tick.C
// clean entries
}
}

View File

@@ -1,13 +1,21 @@
package sqlite3
import "time"
// Config defines the config for storage.
type Config struct {
GCInterval time.Duration
}
// ConfigDefault is the default config
var ConfigDefault = Config{}
var ConfigDefault = Config{
GCInterval: 10 * time.Second,
}
// Helper function to set default values
func configDefault(cfg Config) Config {
if int(cfg.GCInterval) == 0 {
cfg.GCInterval = ConfigDefault.GCInterval
}
return cfg
}

View File

@@ -4,6 +4,7 @@ import "time"
// Storage interface that is implemented by storage providers
type Storage struct {
gcInterval time.Duration
}
// New creates a new storage
@@ -16,10 +17,15 @@ func New(config ...Config) *Storage {
cfg = configDefault(config[0])
}
// TODO
_ = cfg
// Create storage
store := &Storage{
gcInterval: cfg.GCInterval,
}
return &Storage{}
// Start garbage collector
go store.gc()
return store
}
// Get value by key
@@ -41,3 +47,12 @@ func (s *Storage) Delete(key string) error {
func (s *Storage) Clear() error {
return nil
}
// Garbage collector to delete expired keys
func (s *Storage) gc() {
tick := time.NewTicker(s.gcInterval)
for {
<-tick.C
// clean entries
}
}