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.
29 lines
640 B
29 lines
640 B
package cache |
|
|
|
import ( |
|
"fmt" |
|
"time" |
|
) |
|
|
|
// CachedPage represents a cached HTML page |
|
type CachedPage struct { |
|
Content string |
|
ETag string |
|
LastUpdated time.Time |
|
Compressed []byte // Pre-compressed gzip content |
|
} |
|
|
|
// IsStale checks if the cached page is stale based on maxAge |
|
func (cp *CachedPage) IsStale(maxAge time.Duration) bool { |
|
return time.Since(cp.LastUpdated) > maxAge |
|
} |
|
|
|
// GenerateETag generates an ETag for the content |
|
func GenerateETag(content string) string { |
|
// Simple ETag based on content hash |
|
hash := 0 |
|
for _, b := range []byte(content) { |
|
hash = hash*31 + int(b) |
|
} |
|
return fmt.Sprintf(`"%x"`, hash) |
|
}
|
|
|