Skip to content

Commit

Permalink
fix: rename sess.CacheAll method to sess.Cache
Browse files Browse the repository at this point in the history
  • Loading branch information
vividvilla committed Jun 1, 2024
1 parent 65e1767 commit cc187ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ func (s *Session) deleteCache(key ...string) {
}
}

// CacheAll loads session values into memory for quick access.
// Cache loads session values into memory for quick access.
// Ideal for centralized session fetching, e.g., in middleware.
// Subsequent Get/GetMulti calls return cached values, avoiding store access.
// Use ResetCache() to ensure GetAll/Get/GetMulti fetches from the store.
func (s *Session) CacheAll() error {
func (s *Session) Cache() error {
all, err := s.manager.store.GetAll(s.id)
if err != nil {
return err
Expand Down
16 changes: 8 additions & 8 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,13 @@ func TestCacheAll(t *testing.T) {

// Test error.
str.err = errors.New("store error")
err = sess.CacheAll()
err = sess.Cache()
assert.ErrorIs(t, str.err, err)
assert.Nil(t, sess.cache)

// Test without error.
str.err = nil
err = sess.CacheAll()
err = sess.Cache()
assert.NoError(t, err)
assert.Equal(t, str.data, sess.cache)
}
Expand All @@ -258,7 +258,7 @@ func TestResetCache(t *testing.T) {
}
mgr := newMockManager(str)
sess, _ := mgr.NewSession(nil, nil)
sess.CacheAll()
sess.Cache()
assert.Equal(t, str.data, sess.cache)

sess.ResetCache()
Expand Down Expand Up @@ -367,7 +367,7 @@ func TestSet(t *testing.T) {
assert.Nil(t, sess.cache)

// Cache and set.
err = sess.CacheAll()
err = sess.Cache()
assert.NoError(t, err)
err = sess.Set("key1", 1)
assert.NoError(t, err)
Expand Down Expand Up @@ -401,7 +401,7 @@ func TestSetMulti(t *testing.T) {

// Cache and set.
str.data = map[string]interface{}{}
err = sess.CacheAll()
err = sess.Cache()
assert.NoError(t, err)
err = sess.SetMulti(data)
assert.NoError(t, err)
Expand Down Expand Up @@ -432,7 +432,7 @@ func TestDelete(t *testing.T) {
assert.NotContains(t, str.data, "key1")

// Cache and set.
err = sess.CacheAll()
err = sess.Cache()
assert.NoError(t, err)
err = sess.Delete("key2")
assert.NoError(t, err)
Expand Down Expand Up @@ -478,7 +478,7 @@ func TestClear(t *testing.T) {
mgr = newMockManager(str)
sess, err = mgr.NewSession(nil, nil)
assert.NoError(t, err)
err = sess.CacheAll()
err = sess.Cache()
assert.NoError(t, err)
assert.NotNil(t, sess.cache)
err = sess.Clear()
Expand Down Expand Up @@ -529,7 +529,7 @@ func TestDestroy(t *testing.T) {
"key2": 2,
}
assert.NoError(t, err)
err = sess.CacheAll()
err = sess.Cache()
assert.NoError(t, err)
assert.NotNil(t, sess.cache)
err = sess.Clear()
Expand Down

0 comments on commit cc187ff

Please sign in to comment.