当前位置: 首页>>代码示例>>Golang>>正文


Golang Cache.HasRecord方法代码示例

本文整理汇总了Golang中github.com/shingetsu-gou/shingetsu-gou/thread.Cache.HasRecord方法的典型用法代码示例。如果您正苦于以下问题:Golang Cache.HasRecord方法的具体用法?Golang Cache.HasRecord怎么用?Golang Cache.HasRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/shingetsu-gou/shingetsu-gou/thread.Cache的用法示例。


在下文中一共展示了Cache.HasRecord方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: printThreadHead

//printThreadHead renders head part of thread page with cookie.
func (t *threadCGI) printThreadHead(path, id string, page int, ca *thread.Cache, rss string) error {
	switch {
	case ca.HasRecord():
		if !t.IsBot() {
			download.GetCache(true, ca)
		} else {
			log.Println("bot detected, not get cache")
		}
	case t.CheckGetCache():
		ca.Subscribe()
		if t.Req.FormValue("search_new_file") == "" {
			download.GetCache(true, ca)
		}
	default:
		t.Print404(nil, id)
		return errors.New("no records")
	}
	var access string
	var newcookie []*http.Cookie
	if ca.HasRecord() && id == "" && page == 0 {
		cookie, err := t.Req.Cookie("access")
		if err == nil {
			access = cookie.Value
		} else {
			log.Println(err)
		}
		newcookie = t.setCookie(ca, access)
	}
	t.Header(path, rss, newcookie, false)
	return nil
}
开发者ID:shingetsu-gou,项目名称:shingetsu-gou,代码行数:32,代码来源:thread_cgi.go

示例2: bg

//bg waits for at least one record in the cache.
func bg(c *thread.Cache, wg *sync.WaitGroup) {
	w := 2 * time.Second
	newest, err := recentlist.Newest(c.Datfile)
	var done chan struct{}
	go func() {
		wg.Wait()
		done <- struct{}{}
	}()
	if err == nil && (newest.Stamp == c.Stamp()) {
		return
	}
	for {
		select {
		case <-done:
			return
		case <-time.After(w):
			w += time.Second
			if c.HasRecord() || w >= 5*time.Second {
				return
			}
		}
	}
}
开发者ID:shingetsu-gou,项目名称:shingetsu-gou,代码行数:24,代码来源:download.go

示例3: setFromCache

//setFromCache adds cache.datfile/timestamp pair if not exists.
func setFromCache(tx *bolt.Tx, ca *thread.Cache) {
	_, err := getTime(tx, ca.Datfile)
	if err == nil {
		return
	}
	var firstStamp int64
	rec := ca.LoadRecords(record.Alive)
	switch {
	case !ca.HasRecord():
		firstStamp = ca.RecentStamp()
	case len(rec) > 0:
		firstStamp = rec[rec.Keys()[0]].Stamp
	default:
		firstStamp = time.Now().Add(-24 * time.Hour).Unix()
	}
	for {
		_, err = getThread(tx, firstStamp)
		if err != nil {
			break
		}
		firstStamp++
	}
	setEntry(tx, firstStamp, ca.Datfile)
}
开发者ID:shingetsu-gou,项目名称:shingetsu-gou,代码行数:25,代码来源:keylib.go

示例4: printThreadTop

//printThreadTop renders toppart of thread page.
func (t *threadCGI) printThreadTop(path, id string, nPage int, ca *thread.Cache) {
	var lastrec *record.Record
	var resAnchor string
	recs := ca.LoadRecords(record.Alive)
	ids := recs.Keys()
	if ca.HasRecord() && nPage == 0 && id == "" && len(ids) > 0 {
		lastrec = recs[ids[len(ids)-1]]
		resAnchor = t.ResAnchor(lastrec.ID[:8], cfg.ThreadURL, t.Path(), false)
	}
	s := struct {
		Path      string
		Cache     *thread.Cache
		Lastrec   *record.Record
		ResAnchor template.HTML
		cgi.Defaults
	}{
		path,
		ca,
		lastrec,
		template.HTML(resAnchor),
		*t.Defaults(),
	}
	cgi.RenderTemplate("thread_top", s, t.WR)
}
开发者ID:shingetsu-gou,项目名称:shingetsu-gou,代码行数:25,代码来源:thread_cgi.go


注:本文中的github.com/shingetsu-gou/shingetsu-gou/thread.Cache.HasRecord方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。