https://github.com/core-go/cache
https://github.com/core-go/cache
cache memory-cache
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/core-go/cache
- Owner: core-go
- Created: 2021-06-05T09:56:22.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-10-08T15:27:04.000Z (over 3 years ago)
- Last Synced: 2025-01-10T04:15:04.856Z (6 months ago)
- Topics: cache, memory-cache
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Cache
- CacheService
- MemoryCacheService
- RedisService of [core-go/redis](https://github.com/core-go/redis) is an implementation of CacheService## Installation
Please make sure to initialize a Go module before installing core-go/cache:```shell
go get -u github.com/core-go/cache
```Import:
```go
import "github.com/core-go/cache"
```## Example
```go
package mainimport (
"fmt"
"github.com/core-go/cache"
"github.com/core-go/redis"
"time"
)type User struct {
FirstName string `json:"firstName,omitempty"`
LastName string `json:"lastName,omitempty"`
Email string `json:"email,omitempty"`
}func main() {
user := User{
FirstName: "Peter",
LastName: "Parker",
Email: "[email protected]",
}//Example for MemoryCacheService
cacheConfig := cache.CacheConfig{
Size: 10*1024*1024,
CleaningEnable: true,
CleaningInterval: 10 * time.Minute}
cacheService, _ := cache.NewMemoryCacheService(cacheConfig)
cacheService.Put("user", &user, 10 * time.Hour)data, _ := cacheService.Get("user")
fmt.Println("user in cache: ", data)//Example for RedisService
redisService, _ := redis.NewRedisService("redis://localhost:6379")
redisService.Put("user", &user, 0)redisData, _ := redisService.Get("user")
fmt.Println("user in redis: ", redisData)
}
```