Пример #1
0
func writeCacheControlHeaders(u utils.Utils, w http.ResponseWriter, r *http.Request) {
	ttl := utils.ConfigGetTtlDefault(u)
	w.Header().Set("Cache-Control", fmt.Sprintf("public; max-age=%d", ttl))

	expires := time.Now().Add(time.Duration(ttl) * time.Second)
	w.Header().Set("Expires", expires.Format(time.RFC1123))
}
Пример #2
0
func setCaches(u utils.Utils, caches *sliceCache) {
	if caches == nil || len(*caches) < 1 {
		return
	}

	items := make([]utils.MemoryItem, len(*caches))
	ttlMemory := utils.ConfigGetIntWithDefault(u, "TTL_MEMORY", 86400)
	ttlDefault := utils.ConfigGetTtlDefault(u)
	ttlRestricted := utils.ConfigGetIntWithDefault(u, "TTL_RESTRICTED", 60)

	for index, cache := range *caches {
		valueTtl := ttlDefault
		if cache.Count < 1 {
			valueTtl = ttlRestricted
		}

		items[index] = utils.MemoryItem{
			Key:   getCacheKey(cache),
			Value: fmt.Sprintf("%d;%d", cache.Count, time.Now().Unix()+valueTtl),
			Ttl:   ttlMemory,
		}
	}

	if err := u.MemorySet(&items); err != nil {
		u.Errorf("u.MemorySet(%d) error %v", len(items), err)
	}
}