cache.go 597 B

12345678910111213141516171819202122232425262728293031323334
  1. package cache
  2. import (
  3. "time"
  4. "github.com/patrickmn/go-cache"
  5. "github.com/zu1k/proxypool/pkg/proxy"
  6. )
  7. var c = cache.New(cache.NoExpiration, 10*time.Minute)
  8. func GetProxies(key string) proxy.ProxyList {
  9. result, found := c.Get(key)
  10. if found {
  11. return result.(proxy.ProxyList)
  12. }
  13. return nil
  14. }
  15. func SetProxies(key string, proxies proxy.ProxyList) {
  16. c.Set(key, proxies, cache.NoExpiration)
  17. }
  18. func SetString(key, value string) {
  19. c.Set(key, value, cache.NoExpiration)
  20. }
  21. func GetString(key string) string {
  22. result, found := c.Get(key)
  23. if found {
  24. return result.(string)
  25. }
  26. return ""
  27. }