Giter Site home page Giter Site logo

go-firestorm's People

Contributors

jacksgt avatar jschoedt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

go-firestorm's Issues

How to use cache?

Hello,

thanks you for this simple and straightforward package!

I'm successfully using in one of my current projects. The DB interface works perfectly fine, however I have difficulties getting the caching layer to work.

I have written a little middleware that injects the CacheHandler.

func CacheMiddleware(next http.Handler) http.Handler {
	return firestorm.CacheHandler(next.ServeHTTP)
}

and adding it to my router (go-chi):

r.Use(db.CacheMiddleware)
r.Get("/", indexHandler)

From each of my HTTP handlers, I'm then passing the context onto the db functions:

func countryHandler(w http.ResponseWriter, r *http.Request) {
    ...
	countryData, err := LoadCountryData(r.Context())
	if err != nil {
		log.Printf("Failed to load  data: %s", err)
		http.Error(w, "Internal Server Error", 500)
		return
	}
    ...
}

// var Client *firestorm.FSClient was initialized somewhere else
func LoadCountryData(ctx context.Context) (*types.Country, error) {
	var c = &types.Country{ID: slug}
	_, err := Client.NewRequest().SetLoadPaths(firestorm.AllEntities).GetEntities(ctx, c)()
	if IsNotFoundError(err) {
		return nil, nil
	} else if err != nil {
		return nil, err
	}

	return c, nil
}

Nevertheless, I still get the message "Warning. Consider adding the CacheHandler middleware for the session cache to work" and subsequent database calls don't seem to be faster.

Am I using the cache (in)correctly? Is there a way I can verify its behavior?

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.