Skip to content

Commit 675a35f

Browse files
committed
refactor: reorganize package structure following Go conventions
- Move public packages (backend, eviction, stats, middleware) to pkg/ directory - Move internal packages (serializer, introspect) to internal/ directory - Consolidate constants and enums into internal/constants package - Extract CacheBackendChecker to internal/introspect package - Update all import paths to reflect new package organization - Add comprehensive package documentation with usage examples - Extract startBackgroundJobs method to reduce cyclomatic complexity - Fix type consistency in eviction loop (int64 → uint) - Add security linting suppressions where appropriate This restructuring follows Go project layout conventions, improves code organization, and clearly separates public APIs from internal implementations. The pkg/ directory contains packages intended for external use while internal/ contains implementation details not meant for external consumption.
1 parent 0262dbc commit 675a35f

43 files changed

Lines changed: 266 additions & 179 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ bench:
1616

1717
# run-example runs the example specified in the example variable with the optional arguments specified in the ARGS variable.
1818
run-example:
19-
go run __examples/$(example)/*.go $(ARGS)
19+
go run ./__examples/$(example)/*.go $(ARGS)
2020

2121
update-deps:
2222
go get -v -u ./...

__examples/eviction/eviction.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import (
88
"time"
99

1010
"github.com/hyp3rd/hypercache"
11-
"github.com/hyp3rd/hypercache/backend"
1211
"github.com/hyp3rd/hypercache/internal/constants"
13-
"github.com/hyp3rd/hypercache/types"
12+
"github.com/hyp3rd/hypercache/pkg/backend"
1413
)
1514

1615
const cacheCapacity = 10
@@ -68,7 +67,7 @@ func executeExample(evictionInterval time.Duration) {
6867
log.Println("listing all items in the cache")
6968

7069
// Apply filters
71-
sortByFilter := backend.WithSortBy(types.SortByKey.String())
70+
sortByFilter := backend.WithSortBy(constants.SortByKey.String())
7271

7372
items, err := cache.List(context.TODO(), sortByFilter)
7473
if err != nil {

__examples/list/list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"time"
99

1010
"github.com/hyp3rd/hypercache"
11-
"github.com/hyp3rd/hypercache/backend"
11+
"github.com/hyp3rd/hypercache/internal/constants"
12+
"github.com/hyp3rd/hypercache/pkg/backend"
1213
"github.com/hyp3rd/hypercache/pkg/cache"
13-
"github.com/hyp3rd/hypercache/types"
1414
)
1515

1616
const (
@@ -53,7 +53,7 @@ func main() {
5353
return item.Value != "val8"
5454
}
5555

56-
sortByFilter := backend.WithSortBy(types.SortByExpiration.String())
56+
sortByFilter := backend.WithSortBy(constants.SortByExpiration.String())
5757

5858
sortOrder := backend.WithSortOrderAsc(true)
5959

__examples/redis/redis.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import (
77
"time"
88

99
"github.com/hyp3rd/hypercache"
10-
"github.com/hyp3rd/hypercache/backend"
1110
"github.com/hyp3rd/hypercache/backend/redis"
1211
"github.com/hyp3rd/hypercache/internal/constants"
12+
"github.com/hyp3rd/hypercache/pkg/backend"
1313
"github.com/hyp3rd/hypercache/pkg/cache"
14-
"github.com/hyp3rd/hypercache/types"
1514
)
1615

1716
const (
@@ -68,7 +67,7 @@ func main() {
6867
return item.Value != "value-16"
6968
}
7069

71-
sortByFilter := backend.WithSortBy(types.SortByKey.String())
70+
sortByFilter := backend.WithSortBy(constants.SortByKey.String())
7271
// sortOrderFilter := backend.WithSortOrderAsc(true)
7372

7473
// Create a filterFuncFilter with the defined filter function

__examples/service/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"os"
88

99
"github.com/hyp3rd/hypercache"
10-
"github.com/hyp3rd/hypercache/middleware"
10+
"github.com/hyp3rd/hypercache/pkg/middleware"
1111
)
1212

1313
const (

__examples/size/size.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"time"
99

1010
"github.com/hyp3rd/hypercache"
11-
"github.com/hyp3rd/hypercache/backend"
1211
"github.com/hyp3rd/hypercache/internal/constants"
12+
"github.com/hyp3rd/hypercache/pkg/backend"
1313
)
1414

1515
const (

__examples/stats/stats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"time"
88

99
"github.com/hyp3rd/hypercache"
10-
"github.com/hyp3rd/hypercache/backend"
1110
"github.com/hyp3rd/hypercache/internal/constants"
11+
"github.com/hyp3rd/hypercache/pkg/backend"
1212
)
1313

1414
const (

backend/backend.go

Lines changed: 0 additions & 33 deletions
This file was deleted.

config.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
// Package hypercache provides a high-performance, generic caching library with configurable backends and eviction algorithms.
2+
// It supports multiple backend types including in-memory and Redis, with various eviction strategies like LRU, LFU, ARC, and more.
3+
// The package is designed to be flexible and extensible, allowing users to customize cache behavior through configuration options.
4+
//
5+
// Example usage:
6+
//
7+
// config := hypercache.NewConfig[string]("inmemory")
8+
// cache := hypercache.NewHyperCache[string](config)
9+
// cache.Set("key", "value", time.Hour)
10+
// value, found := cache.Get("key")
111
package hypercache
212

313
import (
414
"strings"
515
"time"
616

7-
"github.com/hyp3rd/hypercache/backend"
817
"github.com/hyp3rd/hypercache/internal/constants"
18+
"github.com/hyp3rd/hypercache/pkg/backend"
919
)
1020

1121
// Config is a struct that wraps all the configuration options to setup `HyperCache` and its backend.

cspell.config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ words:
2727
- funlen
2828
- gitversion
2929
- GITVERSION
30+
- goccy
3031
- GOFILES
3132
- gofumpt
3233
- goimports
3334
- golines
3435
- GOPATH
36+
- gosec
3537
- honnef
3638
- ireturn
3739
- Itemm

0 commit comments

Comments
 (0)