muesli / cache2go

Concurrency-safe Go caching library with expiration capabilities and access counters

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Panic occurs when you use the new create struct to access the key

sandaawa opened this issue · comments

Hello, I am a Golang novice. When I was learning your code, I found that I used new() to create the struct. When I access the data, panic prompt Err :nil.Is this a bug?

You shouldn't usually use new to allocate a struct in Go. There's no such thing as a constructor, but you'll typically find methods that initialize the struct. In idiomatic Go that would be NewCache or NewTable, but cache2go has a fairly old and established API, so here it works something like this:

cache := cache2go.Cache("myCache")

Please refer to the README and examples for more information on how to use cache2go.