예제 #1
0
func IdByIdent(ident string) int64 {
	if ident == "" {
		return 0
	}

	val := g.BlogCacheGet(ident)
	if val == nil {
		if p := OneByIdentInDB(ident); p != nil {
			g.BlogCachePut(ident, p.Id)
			return p.Id
		} else {
			return 0
		}
	}

	return val.(int64)
}
예제 #2
0
func ReadBlogContent(b *Blog) *BlogContent {
	if b.Id <= 0 || b.BlogContentId <= 0 {
		return nil
	}

	key := fmt.Sprintf("content_of_%d_%d", b.Id, b.BlogContentLastUpdate)
	val := g.BlogCacheGet(key)
	if val == nil {
		if p := readBlogContentInDB(b); p != nil {
			g.BlogCachePut(key, *p)
			return p
		}
		return nil
	}
	ret := val.(BlogContent)
	return &ret
}
예제 #3
0
func OneById(id int64) *Blog {
	if id <= 0 {
		return nil
	}

	key := fmt.Sprintf("%d", id)
	val := g.BlogCacheGet(key)
	if val == nil {
		if p := OneByIdInDB(id); p != nil {
			g.BlogCachePut(key, *p)
			return p
		}
		return nil
	}
	ret := val.(Blog)
	return &ret
}
예제 #4
0
func Ids(catalog_id int64) []int64 {
	if catalog_id <= 0 {
		return []int64{}
	}

	key := fmt.Sprintf("article_ids_of_%d", catalog_id)
	val := g.BlogCacheGet(key)
	if val == nil {
		if ids := IdsInDB(catalog_id); len(ids) != 0 {
			g.BlogCachePut(key, ids)
			return ids
		} else {
			return []int64{}
		}
	}

	return val.([]int64)
}