mirror of
https://github.com/gofiber/storage.git
synced 2025-10-03 07:46:42 +08:00
🦴 update skeleton
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@ func New(config ...Config) *Storage {
|
||||
gcInterval: cfg.GCInterval,
|
||||
}
|
||||
|
||||
// start garbage collector
|
||||
// Start garbage collector
|
||||
go store.gc()
|
||||
|
||||
return store
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user