fix bug
This commit is contained in:
		
							parent
							
								
									3888bcb8cd
								
							
						
					
					
						commit
						bea6d37069
					
				
							
								
								
									
										8
									
								
								cache.go
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								cache.go
									
									
									
									
									
								
							@ -166,7 +166,7 @@ func (c *localCacher[T]) GetFromCache(id string, options ...Option) (t *T, err e
 | 
				
			|||||||
	if c.cacheDuration.Nanoseconds() > 0 {
 | 
						if c.cacheDuration.Nanoseconds() > 0 {
 | 
				
			||||||
		var earliestCreateTime = time.Now().Add(-c.cacheDuration)
 | 
							var earliestCreateTime = time.Now().Add(-c.cacheDuration)
 | 
				
			||||||
		if a.CreateTime.Before(earliestCreateTime) {
 | 
							if a.CreateTime.Before(earliestCreateTime) {
 | 
				
			||||||
			log.Infof("cache(%s) is in redis cache but expired", id)
 | 
								log.Infof("cache(%s) is in local cache but expired", id)
 | 
				
			||||||
			//TODO: cocurrent
 | 
								//TODO: cocurrent
 | 
				
			||||||
			delete(c.cacheItems, id)
 | 
								delete(c.cacheItems, id)
 | 
				
			||||||
			return nil, ErrNotFound
 | 
								return nil, ErrNotFound
 | 
				
			||||||
@ -297,9 +297,9 @@ func (c *cacher[T]) GetFromCache(id string, options ...Option) (dat *T, err erro
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Step 3. get from [redis]
 | 
						// Step 3. get from [redis]
 | 
				
			||||||
	if c.redisCache != nil {
 | 
						if c.redisCache != nil {
 | 
				
			||||||
		if opt.withCreateTime == nil { //get create time from redis
 | 
							//if opt.withCreateTime == nil { //get create time from redis
 | 
				
			||||||
			options = append(options, OptWithCreateTime, new(time.Time))
 | 
							//	options = append(options, OptWithCreateTime, new(time.Time))
 | 
				
			||||||
		}
 | 
							//}
 | 
				
			||||||
		if dat, err := c.redisCache.GetFromCache(id, options...); err == nil {
 | 
							if dat, err := c.redisCache.GetFromCache(id, options...); err == nil {
 | 
				
			||||||
			if c.localCache != nil {
 | 
								if c.localCache != nil {
 | 
				
			||||||
				c.localCache.SetIntoCache(id, dat, options...) //set create time from redis
 | 
									c.localCache.SetIntoCache(id, dat, options...) //set create time from redis
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user