Giter Club home page Giter Club logo

Comments (2)

karlseguin avatar karlseguin commented on August 25, 2024

fetch doesn't do anything fancy (e.g., there's no singleflight mechanism), so it isn't too burdensome to re-implement it in your app to behave how you want.

Essentially, fetch is currently:

	item := c.Get(key)
	if item != nil && !item.Expired() {
		return item, nil
	}
	value, err := fetch()
	if err != nil {
		return nil, err
	}
	return c.set(key, value, duration, false), nil

You could simply remove the item.Expired() check:

	item := c.Get(key)
	if item != nil {
		return item, nil
	}
	value, err := fetch()
	if err != nil {
		return nil, err
	}
	return c.set(key, value, duration, false), nil

As-is, items are only evicted when the cache is full. Alternative, I'd recommend just using a very large ttl:

const MAX_TTL = time.Duration(1<<63 - 1)

from ccache.

eli-darkly avatar eli-darkly commented on August 25, 2024

Fair enough. As I mentioned in my comment on the other issue, I'd recommend updating the doc comment on Fetch to clarify that it's not doing anything you can't do exactly as well with Get and Set (I wasn't 100% sure at first because it's calling the private set rather than the exported Set—that's also the case above, so your example code wouldn't actually compile if implemented outside the package—but when I followed through to the implementation of set I could see that there's nothing special there).

from ccache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.