aurum / plugin / aurum / cache.vim

"▶1
scriptencoding utf-8
if !exists('s:_pluginloaded')
    execute frawor#Setup('2.0', {'@/resources': '0.0',
                \                  '@/options': '0.0',}, 0)
    finish
elseif s:_pluginloaded
    finish
elseif !exists('s:_loading')
    call FraworLoad(s:_frawor.id)
    finish
endif
let s:_options={
            \'branchcachetime': {'default': 2, 'checker': 'range 0 inf'},
            \'cscachetime':     {'default': 3, 'checker': 'range 0 inf'},
            \'statuscachetime': {'default': 5, 'checker': 'range 0 inf'},
            \'repocachetime':   {'default': 7, 'checker': 'range 0 inf'},
        \}
let s:cachebvars={}
"▶1 bufwipeout
function s:F.bufwipeout()
    let buf=+expand('<abuf>')
    if has_key(s:cachebvars, buf)
        unlet s:cachebvars[buf]
    endif
endfunction
augroup AurumCacheBufVars
    autocmd BufWipeOut,BufFilePost * :call s:F.bufwipeout()
augroup END
let s:_augroups+=['AurumCacheBufVars']
"▶1 getcbvar ::  () + buf, cachebvars → cbvar + cachebvars?
function s:F.getcbvar()
    let buf=bufnr('%')
    if !has_key(s:cachebvars, buf)
        let s:cachebvars[buf]={}
    endif
    return s:cachebvars[buf]
endfunction
"▶1 getcachedval :: key, func, args, dict → val + cbvar
function s:F.getcachedval(key, Func, args, dict)
    let cbvar=s:F.getcbvar()
    if !(has_key(cbvar, a:key) &&
                \localtime()-cbvar['_time'.a:key]<cbvar['_maxtime'.a:key])
        let cbvar[a:key]=call(a:Func, a:args, a:dict)
        let cbvar['_time'.a:key]=localtime()
        if !has_key(cbvar, '_maxtime'.a:key)
            let cbvar['_maxtime'.a:key]=s:_f.getoption(a:key.'cachetime')
        endif
    endif
    return cbvar[a:key]
endfunction
"▶1 delcachedval :: key
function s:F.delcachedval(key)
    let buf=bufnr('%')
    if !has_key(s:cachebvars, buf)
        return
    endif
    let cbvar=s:cachebvars[buf]
    if has_key(cbvar, a:key)
        unlet cbvar[a:key]
    endif
endfunction
"▶1 Post cache resource
call s:_f.postresource('cache', {'get': s:F.getcachedval,
            \                    'del': s:F.delcachedval,
            \               'getcbvar': s:F.getcbvar,})
"▶1
call frawor#Lockvar(s:, '_pluginloaded,cachebvars')
" vim: ft=vim ts=4 sts=4 et fmr=▶,▲
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.