diff --git a/cache.go b/cache.go index fb62b66..163528c 100644 --- a/cache.go +++ b/cache.go @@ -199,7 +199,6 @@ type Session struct { // NewSession creates and initialises a Session. func NewSession(dir, sessionID string) *Session { s := &Session{sessionID, NewCache(dir)} - s.Clear(false) // Clear old session data return s } @@ -263,8 +262,8 @@ func (s *Session) LoadJSON(name string, v interface{}) error { // data are cached & returned. // // If maxAge is 0, any cached data are always returned. -func (s *Session) LoadOrStore(name string, maxAge time.Duration, reload func() ([]byte, error)) ([]byte, error) { - return s.cache.LoadOrStore(s.name(name), maxAge, reload) +func (s *Session) LoadOrStore(name string, reload func() ([]byte, error)) ([]byte, error) { + return s.cache.LoadOrStore(s.name(name), 0, reload) } // LoadOrStoreJSON loads JSON-serialised data from cache if they exist and are @@ -272,8 +271,8 @@ func (s *Session) LoadOrStore(name string, maxAge time.Duration, reload func() ( // is called, and the returned interface{} is cached and returned. // // If maxAge is 0, any cached data are always returned. -func (s *Session) LoadOrStoreJSON(name string, maxAge time.Duration, reload func() (interface{}, error), v interface{}) error { - return s.cache.LoadOrStoreJSON(s.name(name), maxAge, reload, v) +func (s *Session) LoadOrStoreJSON(name string, reload func() (interface{}, error), v interface{}) error { + return s.cache.LoadOrStoreJSON(s.name(name), 0, reload, v) } // Exists returns true if the named cache exists. diff --git a/cache_test.go b/cache_test.go index 1402866..2000d3c 100644 --- a/cache_test.go +++ b/cache_test.go @@ -439,7 +439,8 @@ func TestSession(t *testing.T) { t.Errorf("cached data do not exist: %s", n) } - NewSession(dir, sid2) + s = NewSession(dir, sid2) + s.Clear(false) if s.Exists(n) { t.Errorf("expired data still exist: %s", n) diff --git a/workflow.go b/workflow.go index 31d9317..6a435cf 100644 --- a/workflow.go +++ b/workflow.go @@ -23,7 +23,7 @@ import ( ) // AwGoVersion is the semantic version number of this library. -const AwGoVersion = "0.9" +const AwGoVersion = "0.10" var ( startTime time.Time // Time execution started @@ -467,7 +467,6 @@ func (wf *Workflow) SessionID() string { wf.sessionID = ev } else { wf.sessionID = NewSessionID() - wf.Var("AW_SESSION_ID", wf.sessionID) } } return wf.sessionID @@ -583,6 +582,9 @@ func (wf *Workflow) Run(fn func()) { } log.Println(util.Pad(vstr, "-", 50)) + // Clear expired session data + wf.Session.Clear(false) + // Catch any `panic` and display an error in Alfred. // Fatal(msg) will terminate the process (via log.Fatal). defer func() { @@ -647,6 +649,8 @@ func (wf *Workflow) WarnEmpty(title, subtitle string) { // workflow complete; sending further responses will have no effect. func SendFeedback() { wf.SendFeedback() } func (wf *Workflow) SendFeedback() *Workflow { + // Set session ID + wf.Var("AW_SESSION_ID", wf.SessionID()) // Truncate Items if MaxResults is set if wf.MaxResults > 0 && len(wf.Feedback.Items) > wf.MaxResults { wf.Feedback.Items = wf.Feedback.Items[0:wf.MaxResults]