-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
294 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/TykTechnologies/tyk/config" | ||
"github.com/TykTechnologies/tyk/storage" | ||
) | ||
|
||
// Purger is an interface that will define how the in-memory store will be purged | ||
// of analytics data to prevent it growing too large | ||
type Purger interface { | ||
PurgeCache() | ||
PurgeLoop(<-chan time.Time) | ||
} | ||
|
||
type RedisPurger struct { | ||
Store storage.Handler | ||
} | ||
|
||
func (r RedisPurger) PurgeLoop(ticker <-chan time.Time) { | ||
for { | ||
<-ticker | ||
r.PurgeCache() | ||
} | ||
} | ||
|
||
func (r *RedisPurger) PurgeCache() { | ||
expireAfter := config.Global().AnalyticsConfig.StorageExpirationTime | ||
if expireAfter == 0 { | ||
expireAfter = 60 // 1 minute | ||
} | ||
|
||
exp, _ := r.Store.GetExp(analyticsKeyName) | ||
if exp <= 0 { | ||
r.Store.SetExp(analyticsKeyName, int64(expireAfter)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.