Skip to content

Commit

Permalink
fix: nil cache support (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
23doors committed Aug 21, 2020
1 parent b3649fa commit 96b2575
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions rediscache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,18 @@ func (c *Cache) VersionedCache(cacheKey, lookup string, val interface{},
}

// Set object through reflect.
vref := reflect.ValueOf(val)
oref := reflect.ValueOf(object)
vref := reflect.ValueOf(val)

if oref.Kind() == reflect.Ptr {
if oref.IsValid() && oref.Kind() == reflect.Ptr && !oref.IsNil() {
oref = oref.Elem()
}

vref.Elem().Set(oref)
if !oref.IsValid() || (oref.Kind() == reflect.Ptr && oref.IsNil()) {
vref.Elem().Set(reflect.Zero(vref.Elem().Type()))
} else {
vref.Elem().Set(oref)
}

item.Object = val
item.Version = version
Expand Down

0 comments on commit 96b2575

Please sign in to comment.