Exemplo n.º 1
0
def cached_comments_children(context, spage):
	def _ck():
		return ("commentkids", spage.path)
	r = context.getcache(_ck())
	if r is not None:
		return r
	# We avoid a proliferation of small cache entries by skipping
	# the disk cache entirely for single-entry/page requests.
	if not rendcache.gen_cache_on(context.cfg) or spage.type == "file":
		r = list(context.model.comments_children(spage))
		context.setcache(_ck(), r)
		return r

	r = rendcache.get_flagged(context, "comments-kids", spage.path,
				  "comments-updated")
	if r:
		context.setcache(_ck(), r)
		return r
	r = list(context.model.comments_children(spage))
	v = rendcache.Validator()
	# TODO: actual validator? What would it be?
	rendcache.store_gen(context, "comments-kids", spage.path,
			    r, v)
	context.setcache(_ck(), r)
	return r
Exemplo n.º 2
0
def cached_comments_children(context, spage):
    def _ck():
        return ("commentkids", spage.path)

    r = context.getcache(_ck())
    if r is not None:
        return r
    # We avoid a proliferation of small cache entries by skipping
    # the disk cache entirely for single-entry/page requests.
    if not rendcache.gen_cache_on(context.cfg) or spage.type == "file":
        r = list(context.model.comments_children(spage))
        context.setcache(_ck(), r)
        return r

    r = rendcache.get_flagged(context, "comments-kids", spage.path,
                              "comments-updated")
    if r:
        context.setcache(_ck(), r)
        return r
    r = list(context.model.comments_children(spage))
    v = rendcache.Validator()
    # TODO: actual validator? What would it be?
    rendcache.store_gen(context, "comments-kids", spage.path, r, v)
    context.setcache(_ck(), r)
    return r
Exemplo n.º 3
0
 def _set_disk_cpc(self, page, plist):
     if not rendcache.cache_on(self.cfg) or page.virtual() or \
        page.type != "dir":
         return
     v = rendcache.Validator()
     v.add_mtime(page)
     ds = {page.path: True}
     # note that Storage .children() (and thus .descendants()
     # et al) never returns directories. This is a bit
     # regrettable.
     for ts, ppath in plist:
         pdir = utils.parent_path(ppath)
         if pdir in ds:
             continue
         ds[pdir] = True
         v.add_mtime(self.model.get_page(pdir))
     rendcache.store_gen(self, "page-kids", page.path, plist, v)
Exemplo n.º 4
0
	def _set_disk_cpc(self, page, plist):
		if not rendcache.cache_on(self.cfg) or page.virtual() or \
		   page.type != "dir":
			return
		v = rendcache.Validator()
		v.add_mtime(page)
		ds = {page.path: True}
		# note that Storage .children() (and thus .descendants()
		# et al) never returns directories. This is a bit
		# regrettable.
		for ts, ppath in plist:
			pdir = utils.parent_path(ppath)
			if pdir in ds:
				continue
			ds[pdir] = True
			v.add_mtime(self.model.get_page(pdir))
		rendcache.store_gen(self, "page-kids", page.path, plist, v)
Exemplo n.º 5
0
def gen_pnpages(context, vdir):
	# Disabled? Skip entirely.
	if not rendcache.gen_cache_on(context.cfg):
		return gen_pnp_direct(context, vdir)

	# Even if we get a cache hit, we must super-validate it. We do so
	# by checking that the timestamps of ourselves and our next and
	# previous links are the same as in the list.
	res = rendcache.fetch_gen(context, vdir.path, 'pnc-kids')
	if res:
		r = steppage_pos(context, context.page.path, res)
		if r and \
		   valid_pos(context, res, r[0]) and \
		   valid_pos(context, res, r[1]) and \
		   valid_pos(context, res, r[2]):
			return pages_from_pos(context, res, r)

	# Miss; generate.
	r = gen_pnp_direct(context, vdir)
	if not r:
		return r
	dl = r[2]

	# The validator for the list is somewhat big; it is the timestamp
	# of every directory in the list, explicitly including the root
	# of the list. Unfortunately we have to manually deduce this from
	# the files in the list, which means that we can accidentally
	# omit a directory that currently has no files. This is really
	# a fault of the cache_page_children() approach, but meh.
	v = rendcache.Validator()
	ds = {}
	v.add_mtime(vdir)
	ds[vdir.path] = True
	for ts, ppath in dl:
		pdir = utils.parent_path(ppath)
		if pdir in ds:
			continue
		ds[pdir] = True
		v.add_mtime(context.model.get_page(pdir))
	rendcache.store_gen(context, 'pnc-kids', vdir.path, dl, v)
	return r