type ObjectCache {} func (r *ObjectCache) Cached(ctx context.Context, key string, callback func() (interface{}, error), storeIntoPtr interface{}) error { // Check cache for object, if it exists, get it from cache, otherwise call callback, store to cache, and put result // into storeIntoPtr pointer } func (app * Application) UserCode(ctx context.Context) (*UserProfile, error) { var ret *UserProfile err := app.Cache.Cached(ctx, "user:" + userID, func() (interface{}, error) { // This is only called if the object isn't in the cache return app.BackingStore.GetUser(ctx, userID) }, &ret) return ret, err }