diff --git a/cache/cache.go b/cache/cache.go index 3c4e8eda2..973e53898 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -12,6 +12,7 @@ import ( type Cache interface { Get(string) (interface{}, error) Set(string, interface{}) error + Delete(string) error } func Get(c context.Context, key string) (interface{}, error) { @@ -22,6 +23,10 @@ func Set(c context.Context, key string, value interface{}) error { return FromContext(c).Set(key, value) } +func Delete(c context.Context, key string) error { + return FromContext(c).Delete(key) +} + // Default creates an in-memory cache with the default // 30 minute expiration period. func Default() Cache { diff --git a/cache/helper.go b/cache/helper.go index 14efc67ff..abf1d91c9 100644 --- a/cache/helper.go +++ b/cache/helper.go @@ -52,3 +52,12 @@ func GetRepos(c context.Context, user *model.User) ([]*model.RepoLite, error) { Set(c, key, repos) return repos, nil } + +// DeleteRepos evicts the cached user repositories from the cache associated +// with the current context. +func DeleteRepos(c context.Context, user *model.User) error { + key := fmt.Sprintf("repos:%s", + user.Login, + ) + return Delete(c, key) +} diff --git a/cache/helper_test.go b/cache/helper_test.go index aeed89e48..f0bd53ab1 100644 --- a/cache/helper_test.go +++ b/cache/helper_test.go @@ -84,6 +84,21 @@ func TestHelper(t *testing.T) { g.Assert(p == nil).IsTrue() g.Assert(err).Equal(fakeErr) }) + + g.It("Should evict repos", func() { + key := fmt.Sprintf("repos:%s", + fakeUser.Login, + ) + + Set(c, key, fakeRepos) + repos, err := Get(c, key) + g.Assert(repos != nil).IsTrue() + g.Assert(err == nil).IsTrue() + + DeleteRepos(c, fakeUser) + repos, err = Get(c, key) + g.Assert(repos == nil).IsTrue() + }) }) } diff --git a/server/queue.go b/server/queue.go index 52fc4bf82..7cdaf863f 100644 --- a/server/queue.go +++ b/server/queue.go @@ -103,6 +103,7 @@ func Update(c *gin.Context) { job.Error = work.Job.Error if build.Status == model.StatusPending { + build.Started = work.Job.Started build.Status = model.StatusRunning store.UpdateBuild(c, build) } diff --git a/server/user.go b/server/user.go index edf45ff22..e2ab0567d 100644 --- a/server/user.go +++ b/server/user.go @@ -3,7 +3,9 @@ package server import ( "encoding/base32" "net/http" + "strconv" + log "github.com/Sirupsen/logrus" "github.com/gin-gonic/gin" "github.com/gorilla/securecookie" @@ -33,7 +35,15 @@ func GetFeed(c *gin.Context) { } func GetRepos(c *gin.Context) { - repos, err := cache.GetRepos(c, session.User(c)) + user := session.User(c) + + flush, _ := strconv.ParseBool(c.Query("flush")) + if flush { + log.Debugf("Evicting repository cache for user %s.", user.Login) + cache.DeleteRepos(c, user) + } + + repos, err := cache.GetRepos(c, user) if err != nil { c.String(500, "Error fetching repository list. %s", err) return