Skip to content

Commit

Permalink
modify go.mod
Browse files Browse the repository at this point in the history
  • Loading branch information
OrlovEvgeny committed Nov 13, 2018
1 parent da75de9 commit bed6964
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions bench_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gomcache
package mcache

import (
"fmt"
Expand Down Expand Up @@ -28,4 +28,4 @@ func BenchmarkRW(b *testing.B) {
mcache.SetPointer(fmt.Sprintf("%d", i), i, time.Second*60)
mcache.GetPointer(fmt.Sprintf("%d", i))
}
}
}
6 changes: 3 additions & 3 deletions gcmap/gcmap_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package gcmap

import (
"context"
safemap "github.com/OrlovEvgeny/go-mcache/safeMap"
"github.com/OrlovEvgeny/go-mcache/safeMap"
"sync"
"time"
)
Expand All @@ -20,12 +20,12 @@ type keyset struct {

//GC garbage clean struct
type GC struct {
storage safemap.SafeMap
storage safeMap.SafeMap
keyChan chan string
}

//NewGC - singleton func, returns *GC struct
func NewGC(ctx context.Context, store safemap.SafeMap) *GC {
func NewGC(ctx context.Context, store safeMap.SafeMap) *GC {
if loadInstance {
return gcInstance
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module github.com/OrlovEvgeny/go-mcache

require github.com/vmihailenco/msgpack v4.0.1+incompatible
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/vmihailenco/msgpack v4.0.1+incompatible h1:RMF1enSPeKTlXrXdOcqjFUElywVZjjC6pqse21bKbEU=
github.com/vmihailenco/msgpack v4.0.1+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
26 changes: 13 additions & 13 deletions mcache.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package gomcache
package mcache

import (
"context"
"github.com/OrlovEvgeny/go-mcache/gcmap"
entity "github.com/OrlovEvgeny/go-mcache/item"
safemap "github.com/OrlovEvgeny/go-mcache/safeMap"
"github.com/OrlovEvgeny/go-mcache/item"
"github.com/OrlovEvgeny/go-mcache/safeMap"
"github.com/vmihailenco/msgpack"
"log"
"time"
)

//
var (
storage safemap.SafeMap
storage safeMap.SafeMap
gc *gcmap.GC
instance *CacheDriver
loadInstance = false
Expand All @@ -21,7 +21,7 @@ var (
//initStore - returns context and context close func. Inited map storage and remove old cache
func initStore() (context.Context, context.CancelFunc) {
ctx, finish := context.WithCancel(context.Background())
storage = safemap.NewStorage()
storage = safeMap.NewStorage()
gc = gcmap.NewGC(ctx, storage)
return ctx, finish
}
Expand Down Expand Up @@ -54,7 +54,7 @@ func (mc *CacheDriver) Get(key string, struc interface{}) bool {
if !ok {
return false
}
item := data.(entity.Item)
item := data.(item.Item)
if item.IsExpire() {
return false
}
Expand All @@ -69,13 +69,13 @@ func (mc *CacheDriver) Get(key string, struc interface{}) bool {
func (mc *CacheDriver) GetPointer(key string) (interface{}, bool) {
data, ok := storage.Find(key)
if !ok {
return entity.Item{}.DataLink, false
return item.Item{}.DataLink, false
}
item := data.(entity.Item)
if item.IsExpire() {
return entity.Item{}.DataLink, false
entity := data.(item.Item)
if entity.IsExpire() {
return item.Item{}.DataLink, false
}
return item.DataLink, true
return entity.DataLink, true
}

//Set - add cache data and serialize/deserialize value
Expand All @@ -87,15 +87,15 @@ func (mc *CacheDriver) Set(key string, value interface{}, ttl time.Duration) err
log.Println("MCACHE SET ERROR: ", err)
return err
}
storage.Insert(key, entity.Item{Key: key, Expire: expire, Data: v})
storage.Insert(key, item.Item{Key: key, Expire: expire, Data: v})
return nil
}

//SetPointer - add cache &pointer data (more and example info README.md)
func (mc *CacheDriver) SetPointer(key string, value interface{}, ttl time.Duration) error {
expire := time.Now().Local().Add(ttl)
go gc.Expired(mc.ctx, key, ttl)
storage.Insert(key, entity.Item{Key: key, Expire: expire, DataLink: value})
storage.Insert(key, item.Item{Key: key, Expire: expire, DataLink: value})
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion mcache_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gomcache
package mcache

import (
"log"
Expand Down
4 changes: 2 additions & 2 deletions safeMap/safe.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package safeMap

import entity "github.com/OrlovEvgeny/go-mcache/item"
import "github.com/OrlovEvgeny/go-mcache/item"

//safeMap - data command chanel
type safeMap chan commandData
Expand Down Expand Up @@ -134,7 +134,7 @@ func flush(s map[string]interface{}, keys []string) {
if !ok {
continue
}
if value.(entity.Item).IsExpire() {
if value.(item.Item).IsExpire() {
delete(s, v)
}
}
Expand Down

0 comments on commit bed6964

Please sign in to comment.