A simple TicTacToe app with Golang backend and WebSockets gluing it all together.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
830 B

  1. package cache
  2. import (
  3. "sync"
  4. "time"
  5. uuid "github.com/satori/go.uuid"
  6. )
  7. // Item for caching
  8. type Item struct {
  9. Object interface{}
  10. Expiration int64
  11. }
  12. // Cache is a simple in-memory cache for storing things
  13. type Cache struct {
  14. *cache
  15. }
  16. type cache struct {
  17. defaultExpiration time.Duration
  18. items map[uuid.UUID]Item
  19. mu sync.RWMutex
  20. onEvicted func(uuid.UUID, interface{})
  21. janitor *janitor
  22. }
  23. const (
  24. // NoExpiration For use with functions that take an expiration time.
  25. NoExpiration time.Duration = -1
  26. // DefaultExpiration For use with functions that take an expiration time.
  27. // Equivalent to passing in the same expiration duration as was given to
  28. // New() or NewFrom() when the cache was created (e.g. 5 minutes.)
  29. DefaultExpiration time.Duration = time.Hour * 1
  30. )