Skip to content

Commit

Permalink
update module's name
Browse files Browse the repository at this point in the history
  • Loading branch information
knbr13 committed Apr 6, 2024
1 parent 5774c8a commit 4e56b7a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
## in-memdb
## incache

The `inmemdb` package provides a simple in-memory database implementation in Go. It can be used as a package in other Go projects to store key-value pairs in memory. The package is safe to use concurrently with multiple goroutines.
The `incache` package provides a simple cache implementation in Go. It can be used as a package in other Go projects to store key-value pairs in memory. The package is safe to use concurrently with multiple goroutines.

### Installation

To use this package in your Go project, you can install it using `go get`:

```bash
go get github.com/knbr13/inmemdb
go get github.com/knbr13/incache
```

### Usage
Expand All @@ -19,12 +19,12 @@ import (
"fmt"
"time"

inmemdb "github.com/knbr13/in-memdb"
incache "github.com/knbr13/incache"
)

func main() {
// Create a new Cache Builder
cb := inmemdb.New[string, string](3) // 3 is the maximum number of key-value pairs the cache can hold
cb := incache.New[string, string](3) // 3 is the maximum number of key-value pairs the cache can hold

// Build the Cache
db := cb.Build()
Expand Down Expand Up @@ -53,12 +53,12 @@ func main() {
db.Delete("key1")

// Transfer data to another database
anotherCB := inmemdb.New[string, string](2)
anotherCB := incache.New[string, string](2)
anotherDB := anotherCB.Build()
db.TransferTo(anotherDB)

// Copy data to another database
copyCB := inmemdb.New[string, string](2)
copyCB := incache.New[string, string](2)
copyDB := copyCB.Build()
anotherDB.CopyTo(copyDB)

Expand Down
4 changes: 2 additions & 2 deletions cache.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package inmemdb
package incache

import (
"sync"
Expand Down Expand Up @@ -79,7 +79,7 @@ func (b *CacheBuilder[K, V]) Build() Cache[K, V] {
case Manual:
return newManual[K, V](b)
default:
panic("in-memdb: unknown evict-type")
panic("incache: unknown evict-type")
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/knbr13/in-memdb
module github.com/knbr13/incache

go 1.22.0
5 changes: 2 additions & 3 deletions mcache.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package inmemdb
package incache

import (
"time"
Expand All @@ -16,7 +16,7 @@ type valueWithTimeout[V any] struct {
expireAt *time.Time
}

// New creates a new in-memory database instance with optional configuration provided by the specified options.
// New creates a new cache instance with optional configuration provided by the specified options.
// The database starts a background goroutine to periodically check for expired keys based on the configured time interval.
func newManual[K comparable, V any](cacheBuilder *CacheBuilder[K, V]) *MCache[K, V] {
db := &MCache[K, V]{
Expand Down Expand Up @@ -240,7 +240,6 @@ func (c *MCache[K, V]) expireKeys() {
}
}

// Purge clears the cache completely.
func (c *MCache[K, V]) Purge() {
if c.timeInterval > 0 {
c.stopCh <- struct{}{} // Signal the expiration goroutine to stop
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 inmemdb
package incache

import (
"testing"
Expand Down

0 comments on commit 4e56b7a

Please sign in to comment.