Пример #1
0
func (ph *Handler) purgeAll(app types.App, pr purgeRequest) (purgeResult, error) {
	var pres = purgeResult(make(map[string]bool))

	for _, uString := range pr {
		pres[uString] = false
		var u, err = url.Parse(uString)
		if err != nil {
			continue
		}
		var location = app.GetLocationFor(u.Host, u.Path)
		if location == nil {
			ph.logger.Logf(
				"[%p] got request to purge an object (%s) that is for a not configured location",
				ph, uString)
			continue
		}

		var oid = location.NewObjectIDForURL(u)

		parts, err := location.Cache.Storage.GetAvailableParts(oid)

		if err != nil {
			if !os.IsNotExist(err) {
				ph.logger.Errorf(
					"[%p] got error while gettings parts of object '%s' - %s",
					ph, oid, err)
				return nil, err
			}
		}

		if len(parts) == 0 {
			continue
		}

		if err = location.Cache.Storage.Discard(oid); err != nil {
			if !os.IsNotExist(err) {
				ph.logger.Errorf(
					"[%p] got error while purging object '%s' - %s",
					ph, oid, err)
				return nil, err
			}
		}

		location.Cache.Algorithm.Remove(parts...)
		pres[uString] = err == nil // err is os.ErrNotExist
	}
	return pres, nil
}
Пример #2
0
func newStatistics(app types.App, cacheZones map[string]*types.CacheZone) statisticsRoot {
	var zones = make([]zoneStatistics, 0, len(cacheZones))
	for _, cacheZone := range cacheZones {
		var stats = cacheZone.Algorithm.Stats()
		zones = append(zones, zoneStatistics{
			ID:          stats.ID(),
			Hits:        stats.Hits(),
			Requests:    stats.Requests(),
			Objects:     stats.Objects(),
			CacheHitPrc: stats.CacheHitPrc(),
			Size:        stats.Size().Bytes(),
		})
	}

	var appStats = app.Stats()
	return statisticsRoot{
		Requests:      appStats.Requests,
		Responded:     appStats.Responded,
		NotConfigured: appStats.NotConfigured,
		InFlight:      appStats.Requests - appStats.Responded - appStats.NotConfigured,
		CacheZones:    zones,
		Started:       app.Started(),
		Version:       versionFromAppVersion(app.Version()),
	}
}