Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

items never expire? #105

Closed
unisqu opened this issue Nov 10, 2018 · 4 comments
Closed

items never expire? #105

unisqu opened this issue Nov 10, 2018 · 4 comments

Comments

@unisqu
Copy link

unisqu commented Nov 10, 2018

I just realised that my items don't expire within 1 min. how to expire items?

    LifeWindow: 1 * time.Minute,
@cristaloleg
Copy link
Collaborator

Hi, can you show your code? It's hard to guess what you're doing 😉

@shiftregister-vg
Copy link

shiftregister-vg commented Nov 20, 2018

@unisqu I missed it too, you need to also set CleanWindow in your config.

Here's a config that I'm using that does expire items after 30 minutes

cacheConfig := bigcache.Config {
    Shards: 1024,
    LifeWindow: 30 * time.Minute,
    CleanWindow: 30 * time.Minute,
    MaxEntriesInWindow: 1000 * 30 * 60,
    MaxEntrySize: 500,
    Verbose: true,
    HardMaxCacheSize: 1024,
    OnRemove: nil,
    Logger: cacheLog,
}

@siennathesane
Copy link
Collaborator

Closing as resolved. :)

@bonedaddy
Copy link

im getting this error too, I have set a clean window to 1hr, and a lifetime of 12hr, but content is not getting cleaned.

Code:

// NewCache is used to instantiate our bigcache content cache
func NewCache(opts config.Cache) (*Cache, error) {
	// parse content life time into time.Duration
	lifetime, err := time.ParseDuration(opts.Content.LifeTime)
	if err != nil {
		return nil, err
	}
	// parse cache clean window into time.Duration
	cleanwindow, err := time.ParseDuration(opts.Content.CleanWindow)
	if err != nil {
		return nil, err
	}
	// generate a default bigcache config
	cfg := bigcache.DefaultConfig(lifetime)
	// set the maximum size of the cache in megabytes
	cfg.HardMaxCacheSize = opts.Content.MaxSizeInMB
	// set how often we should attempt to clean the cache
	cfg.CleanWindow = cleanwindow
	// instantiate our bigcache
	bc, err := bigcache.NewBigCache(cfg)
	if err != nil {
		return nil, err
	}
	// return the content cache
	return &Cache{
		bc,
	}, nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants