push app/route cache down to datastore (#303)

cache now implements models.Datastore by just embedding one and then changing
GetApp and GetRoute to have the cache inside. this makes it really flexible
for things like testing, so now the agent doesn't automagically do caching,
now it must be passed a datastore that was wrapped with a cache datastore.
the datastore in the server can remain separate and not use the cache still,
and then now the agent when running fn 'for real' is configured with the cache
baked in. this seems a lot cleaner than what we had and gets the cache out of
the way and it's easier to swap in / out / extend.
This commit is contained in:
Reed Allman
2017-09-08 09:18:36 -07:00
committed by Travis Reeder
parent 3d8ca450bb
commit 59d95d660a
4 changed files with 75 additions and 58 deletions

View File

@@ -14,6 +14,7 @@ import (
"github.com/fnproject/fn/api/agent"
"github.com/fnproject/fn/api/common"
"github.com/fnproject/fn/api/datastore"
"github.com/fnproject/fn/api/datastore/cache"
"github.com/fnproject/fn/api/id"
"github.com/fnproject/fn/api/logs"
"github.com/fnproject/fn/api/models"
@@ -74,7 +75,7 @@ func NewFromEnv(ctx context.Context) *Server {
// New creates a new Functions server with the passed in datastore, message queue and API URL
func New(ctx context.Context, ds models.Datastore, mq models.MessageQueue, logDB models.LogStore, opts ...ServerOption) *Server {
s := &Server{
Agent: agent.New(ds, mq),
Agent: agent.New(cache.Wrap(ds), mq), // only add datastore caching to agent
Router: gin.New(),
Datastore: ds,
MQ: mq,