entry.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package entry
  2. import (
  3. "time"
  4. "github.com/kataras/iris/v12/core/memstore"
  5. )
  6. // Entry is the cache entry
  7. // contains the expiration datetime and the response
  8. type Entry struct {
  9. // ExpiresAt is the time which this cache will not be available
  10. lifeTime *memstore.LifeTime
  11. // when `Reset` this value is reseting to time.Now(),
  12. // it's used to send the "Last-Modified" header,
  13. // some clients may need it.
  14. LastModified time.Time
  15. // Response the response should be served to the client
  16. response *Response
  17. // but we need the key to invalidate manually...xmm
  18. // let's see for that later, maybe we make a slice instead
  19. // of store map
  20. }
  21. // reset called each time a new entry is acquired from the pool.
  22. func (e *Entry) reset(lt *memstore.LifeTime, r *Response) {
  23. e.response = r
  24. e.LastModified = lt.Begun
  25. }
  26. // Response returns the cached response as it's.
  27. func (e *Entry) Response() *Response {
  28. return e.response
  29. }
  30. // // Response gets the cache response contents
  31. // // if it's valid returns them with a true value
  32. // // otherwise returns nil, false
  33. // func (e *Entry) Response() (*Response, bool) {
  34. // if !e.isValid() {
  35. // // it has been expired
  36. // return nil, false
  37. // }
  38. // return e.response, true
  39. // }
  40. // // isValid reports whether this entry's response is still valid or expired.
  41. // // If the entry exists in the store then it should be valid anyways.
  42. // func (e *Entry) isValid() bool {
  43. // return !e.lifeTime.HasExpired()
  44. // }