예제 #1
0
파일: sitecache.go 프로젝트: mrmorphic/goss
func getSiteCache() *SiteCache {
	key := "goss.Sitetree"
	result := cache.Get(key)
	if result != nil {
		return result.(*SiteCache)
	}

	c, _ := primeSiteCache()

	if configuration.cacheSiteTreeNavTTL > 0 {
		cache.Store(key, c, time.Duration(configuration.cacheSiteTreeNavTTL)*time.Second)
	}

	return c
}
예제 #2
0
// Return the SiteConfig DataObject.
func (ctl *BaseController) SiteConfig() (obj interface{}, e error) {
	v := cache.Get("goss.SiteConfig")
	if v != nil {
		return v, nil
	}

	q := orm.NewQuery("SiteConfig").Limit(0, 1)
	res, e := q.Run()
	if e != nil {
		return nil, e
	}

	items, _ := res.(orm.DataList).Items()
	if len(items) < 1 {
		return nil, errors.New("There is no SiteConfig record")
	}

	if configuration.cacheSiteConfigTTL > 0 {
		cache.Store("goss.SiteConfig", items[0], time.Duration(configuration.cacheSiteConfigTTL)*time.Second)
	}

	return items[0], nil
}
예제 #3
0
func (ctl *BaseController) Menu(level int) (orm.DataList, error) {
	key := "goss.Menu." + strconv.Itoa(level)
	result := cache.Get(key)
	if result != nil {
		return result.(orm.DataList), nil
	}

	if level == 1 {
		q := orm.NewQuery("SiteTree").Where("\"SiteTree_Live\".\"ParentID\"=0").Where("\"ShowInMenus\"=1").Sort("\"Sort\" ASC")
		v, e := q.Run()
		if e != nil {
			return nil, e
		}

		if configuration.cacheMenuTTL > 0 {
			cache.Store(key, v, time.Duration(configuration.cacheMenuTTL)*time.Second)
		}

		return v.(orm.DataList), nil
	}

	return nil, nil
}