时间选定库
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.

24 lines
374 B

  1. package time_arrow
  2. import "time"
  3. type cache struct {
  4. Expired time.Time
  5. Data string
  6. }
  7. func (c *cache) IsExpired() bool {
  8. return c.Expired.Before(time.Now())
  9. }
  10. func (c *cache) SetData(data string, duration time.Duration) {
  11. c.Data = data
  12. c.Expired = time.Now().Add(duration)
  13. }
  14. func (c *cache) GetData() string {
  15. if c.IsExpired() {
  16. return ""
  17. }
  18. return c.Data
  19. }