fixed broken cache...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-09-01 00:04:13 +03:00
parent 323eb39c1b
commit 4059b988a9
3 changed files with 43 additions and 31 deletions

View File

@ -122,14 +122,20 @@ object.Constructor('BasePage', {
// XXX should this be able to prevent navigation???
onBeforeNavigate: types.event.Event('beforeNavigate'),
onNavigate: types.event.Event('navigate',
function(handle, path){
this.onBeforeNavigate(path)
function(handle, location){
this.onBeforeNavigate(location)
this.referrer = this.location
var {path, args} = pwpath.splitArgs(location)
var cur = this.__location =
this.resolvePathVars(
pwpath.relative(
this.location,
path))
// NOTE: this is done instead of simply assigning
// location as-is to normalize the paths and
// arguments...
pwpath.joinArgs(
pwpath.relative(
this.path,
path),
pwpath.obj2args(args)))
// trigger handlers...
handle() }),
@ -1331,6 +1337,13 @@ function(obj, name, value){
var CachedPage =
module.CachedPage =
object.Constructor('CachedPage', Page, {
// Sets what to use for cache id...
//
// Can be:
// 'location' (default)
// 'path'
cache_id: 'location',
// NOTE: set this to null/undefined/0 to disable...
cache_timeout: '20m',
@ -1343,21 +1356,21 @@ object.Constructor('CachedPage', Page, {
;(this.root ?? this).__cachestore = value },
get cache(){
this.checkCache(this.path)
return ((this.cachestore ?? {})[this.path] ?? {}).value },
this.checkCache(this[this.cache_id])
return ((this.cachestore ?? {})[this[this.cache_id]] ?? {}).value },
// XXX check * paths for matches...
set cache(value){
if(this.cachestore === false
|| this.cache == value){
return }
var path = this.path
var id = this[this.cache_id ?? 'location']
// clear...
if(value == null){
delete (this.cachestore ?? {})[path]
delete (this.cachestore ?? {})[id]
// set...
} else {
var prev = ((this.cachestore = this.cachestore ?? {})[path] ?? {}).value ?? {}
;(this.cachestore = this.cachestore ?? {})[path] = {
var prev = ((this.cachestore = this.cachestore ?? {})[id] ?? {}).value ?? {}
;(this.cachestore = this.cachestore ?? {})[id] = {
created: Date.now(),
// XXX
valid: undefined,
@ -1373,7 +1386,7 @@ object.Constructor('CachedPage', Page, {
// i.e. if we match * as a single path item then we might
// miss creating a subtree (ex: /tree), while matching
// /* to anything will give us lots of false positives...
if(key != path && deps.has(path)){
if(key != id && deps.has(id)){
delete this.cachestore[key] } } },
checkCache: function(...paths){
@ -1665,12 +1678,12 @@ module.System = {
tree: {
text: object.doc`
<macro src="../*">
<div class="item">
<a href="#@source(./path)">@source(./name)</a>
<span class="show-on-hover">
<a href="#@source(./path)/info">&#128712;</a>
<a href="#@source(./path)/delete">&times;</a>
</span>
<div>
<div class="item">
<a href="#@source(./path)">@source(./name)</a>
<a class="show-on-hover" href="#@source(./path)/info">&#128712;</a>
<a class="show-on-hover" href="#@source(./path)/delete">&times;</a>
</div>
<div style="padding-left: 30px">
@source(./tree)
</div>

View File

@ -269,7 +269,6 @@ module = {
: [name, ...this.ALTERNATIVE_PAGES] },
// XXX EXPERIMENTAL...
//
// .splitArgs(<path>)
// -> <spec>
@ -284,8 +283,6 @@ module = {
// }
//
// Syntax:
// <path>/<name>:<value>/<name>:<value>/../action
// XXX or?
// <path> ::= <path>:<args>
// <args> ::=
// <arg> | <arg>:<args>
@ -304,7 +301,7 @@ module = {
path,
args: args.reduce(function(res, arg){
var [name, value] = arg.split(/=(.*)/)
res[name] = value ?? true
res[name.trim()] = value ?? true
return res }, {}),
} },
obj2args: function(args){
@ -313,12 +310,15 @@ module = {
.map(function([key, value]){
return value === true ?
key
//: value === false ?
// []
: key +':'+ (value.toString().replace(/:/g, '\\:'))
})
: key +'='+ ((value + '').replace(/:/g, '\\:')) })
.join(':')
: args },
joinArgs: function(path, args={}){
path = this.join(path)
args = this.obj2args(args)
return args == '' ?
path
: path +':'+ args },
}

View File

@ -1,17 +1,13 @@
/**********************************************************************
*
*
* XXX ASAP prevent paths from using reserved chars like: ":", "#", ...
* XXX FEATURE list macro paging...
* ...should this be macro level or handled in .each()
* what mode?
* - count + block-offset (preferred)
* - count + elem-offset
* - from + to
* XXX what should page caching use?
* - .path (current)
* - .location
* - .path + normalized .args
* ...should this be configurable???
* XXX FEATURE tags and accompanying API...
* - add tags to page -- macro/filter
* <page>.text -> <page>.tags (cached on .update(..))
@ -157,6 +153,9 @@
* - get --
* - download --
* - upload --
* - tags
* - get tags from page --
* - show tagged pages --
* - search
* - paths
* - text