mirror of
https://github.com/gofiber/storage.git
synced 2025-10-04 16:22:52 +08:00
🦴 update skeleton
This commit is contained in:
@@ -1,13 +1,21 @@
|
|||||||
package memcached
|
package memcached
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
// Config defines the config for storage.
|
// Config defines the config for storage.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
GCInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigDefault is the default config
|
// ConfigDefault is the default config
|
||||||
var ConfigDefault = Config{}
|
var ConfigDefault = Config{
|
||||||
|
GCInterval: 10 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
// Helper function to set default values
|
// Helper function to set default values
|
||||||
func configDefault(cfg Config) Config {
|
func configDefault(cfg Config) Config {
|
||||||
|
if int(cfg.GCInterval) == 0 {
|
||||||
|
cfg.GCInterval = ConfigDefault.GCInterval
|
||||||
|
}
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,10 @@
|
|||||||
package memcached
|
package memcached
|
||||||
|
|
||||||
import (
|
import "time"
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Storage interface that is implemented by storage providers
|
// Storage interface that is implemented by storage providers
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
|
gcInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new storage
|
// New creates a new storage
|
||||||
@@ -18,10 +17,15 @@ func New(config ...Config) *Storage {
|
|||||||
cfg = configDefault(config[0])
|
cfg = configDefault(config[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// Create storage
|
||||||
_ = cfg
|
store := &Storage{
|
||||||
|
gcInterval: cfg.GCInterval,
|
||||||
|
}
|
||||||
|
|
||||||
return &Storage{}
|
// Start garbage collector
|
||||||
|
go store.gc()
|
||||||
|
|
||||||
|
return store
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get value by key
|
// Get value by key
|
||||||
@@ -43,3 +47,12 @@ func (s *Storage) Delete(key string) error {
|
|||||||
func (s *Storage) Clear() error {
|
func (s *Storage) Clear() error {
|
||||||
return nil
|
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"
|
import "time"
|
||||||
|
|
||||||
// Config defines the config for memory storage.
|
// Config defines the config for storage.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
GCInterval time.Duration
|
GCInterval time.Duration
|
||||||
}
|
}
|
||||||
|
@@ -33,7 +33,7 @@ func New(config ...Config) *Storage {
|
|||||||
gcInterval: cfg.GCInterval,
|
gcInterval: cfg.GCInterval,
|
||||||
}
|
}
|
||||||
|
|
||||||
// start garbage collector
|
// Start garbage collector
|
||||||
go store.gc()
|
go store.gc()
|
||||||
|
|
||||||
return store
|
return store
|
||||||
|
@@ -1,13 +1,21 @@
|
|||||||
package mysql
|
package mysql
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
// Config defines the config for storage.
|
// Config defines the config for storage.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
GCInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigDefault is the default config
|
// ConfigDefault is the default config
|
||||||
var ConfigDefault = Config{}
|
var ConfigDefault = Config{
|
||||||
|
GCInterval: 10 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
// Helper function to set default values
|
// Helper function to set default values
|
||||||
func configDefault(cfg Config) Config {
|
func configDefault(cfg Config) Config {
|
||||||
|
if int(cfg.GCInterval) == 0 {
|
||||||
|
cfg.GCInterval = ConfigDefault.GCInterval
|
||||||
|
}
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,12 @@
|
|||||||
package mysql
|
package mysql
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// Storage interface that is implemented by storage providers
|
// Storage interface that is implemented by storage providers
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
|
gcInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new storage
|
// New creates a new storage
|
||||||
@@ -16,10 +19,15 @@ func New(config ...Config) *Storage {
|
|||||||
cfg = configDefault(config[0])
|
cfg = configDefault(config[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// Create storage
|
||||||
_ = cfg
|
store := &Storage{
|
||||||
|
gcInterval: cfg.GCInterval,
|
||||||
|
}
|
||||||
|
|
||||||
return &Storage{}
|
// Start garbage collector
|
||||||
|
go store.gc()
|
||||||
|
|
||||||
|
return store
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get value by key
|
// Get value by key
|
||||||
@@ -41,3 +49,12 @@ func (s *Storage) Delete(key string) error {
|
|||||||
func (s *Storage) Clear() error {
|
func (s *Storage) Clear() error {
|
||||||
return nil
|
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
|
package postgres
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
// Config defines the config for storage.
|
// Config defines the config for storage.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
GCInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigDefault is the default config
|
// ConfigDefault is the default config
|
||||||
var ConfigDefault = Config{}
|
var ConfigDefault = Config{
|
||||||
|
GCInterval: 10 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
// Helper function to set default values
|
// Helper function to set default values
|
||||||
func configDefault(cfg Config) Config {
|
func configDefault(cfg Config) Config {
|
||||||
|
if int(cfg.GCInterval) == 0 {
|
||||||
|
cfg.GCInterval = ConfigDefault.GCInterval
|
||||||
|
}
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,12 @@
|
|||||||
package postgres
|
package postgres
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// Storage interface that is implemented by storage providers
|
// Storage interface that is implemented by storage providers
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
|
gcInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new storage
|
// New creates a new storage
|
||||||
@@ -16,10 +19,15 @@ func New(config ...Config) *Storage {
|
|||||||
cfg = configDefault(config[0])
|
cfg = configDefault(config[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// Create storage
|
||||||
_ = cfg
|
store := &Storage{
|
||||||
|
gcInterval: cfg.GCInterval,
|
||||||
|
}
|
||||||
|
|
||||||
return &Storage{}
|
// Start garbage collector
|
||||||
|
go store.gc()
|
||||||
|
|
||||||
|
return store
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get value by key
|
// Get value by key
|
||||||
@@ -41,3 +49,12 @@ func (s *Storage) Delete(key string) error {
|
|||||||
func (s *Storage) Clear() error {
|
func (s *Storage) Clear() error {
|
||||||
return nil
|
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
|
package sqlite3
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
// Config defines the config for storage.
|
// Config defines the config for storage.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
GCInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigDefault is the default config
|
// ConfigDefault is the default config
|
||||||
var ConfigDefault = Config{}
|
var ConfigDefault = Config{
|
||||||
|
GCInterval: 10 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
// Helper function to set default values
|
// Helper function to set default values
|
||||||
func configDefault(cfg Config) Config {
|
func configDefault(cfg Config) Config {
|
||||||
|
if int(cfg.GCInterval) == 0 {
|
||||||
|
cfg.GCInterval = ConfigDefault.GCInterval
|
||||||
|
}
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@ import "time"
|
|||||||
|
|
||||||
// Storage interface that is implemented by storage providers
|
// Storage interface that is implemented by storage providers
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
|
gcInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new storage
|
// New creates a new storage
|
||||||
@@ -16,10 +17,15 @@ func New(config ...Config) *Storage {
|
|||||||
cfg = configDefault(config[0])
|
cfg = configDefault(config[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// Create storage
|
||||||
_ = cfg
|
store := &Storage{
|
||||||
|
gcInterval: cfg.GCInterval,
|
||||||
|
}
|
||||||
|
|
||||||
return &Storage{}
|
// Start garbage collector
|
||||||
|
go store.gc()
|
||||||
|
|
||||||
|
return store
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get value by key
|
// Get value by key
|
||||||
@@ -41,3 +47,12 @@ func (s *Storage) Delete(key string) error {
|
|||||||
func (s *Storage) Clear() error {
|
func (s *Storage) Clear() error {
|
||||||
return nil
|
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