Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

71 lines (61 sloc) 1.902 kb
" cache.vim
" @Author: Thomas Link (micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-06-30.
" @Last Change: 2008-12-20.
" @Revision: 0.1.29
if &cp || exists("loaded_tlib_cache_autoload")
finish
endif
let loaded_tlib_cache_autoload = 1
" :def: function! tlib#cache#Filename(type, ?file=%, ?mkdir=0)
function! tlib#cache#Filename(type, ...) "{{{3
" TLogDBG 'bufname='. bufname('.')
let dir = tlib#var#Get('tlib_cache', 'bg')
if empty(dir)
let dir = tlib#file#Join([tlib#dir#MyRuntime(), 'cache'])
endif
if a:0 >= 1 && !empty(a:1)
let file = a:1
else
if empty(expand('%:t'))
return ''
endif
let file = expand('%:p')
let file = tlib#file#Relative(file, tlib#file#Join([dir, '..']))
endif
" TLogVAR file, dir
let mkdir = a:0 >= 2 ? a:2 : 0
let file = substitute(file, '\.\.\|[:&<>]\|//\+\|\\\\\+', '_', 'g')
let dirs = [dir, a:type]
let dirf = fnamemodify(file, ':h')
if dirf != '.'
call add(dirs, dirf)
endif
let dir = tlib#file#Join(dirs)
" TLogVAR dir
let dir = tlib#dir#PlainName(dir)
" TLogVAR dir
let file = fnamemodify(file, ':t')
" TLogVAR file, dir
if mkdir && !isdirectory(dir)
call mkdir(dir, 'p')
endif
let cache_file = tlib#file#Join([dir, file])
" TLogVAR cache_file
return cache_file
endf
function! tlib#cache#Save(cfile, dictionary) "{{{3
if !empty(a:cfile)
call writefile([string(a:dictionary)], a:cfile, 'b')
endif
endf
function! tlib#cache#Get(cfile) "{{{3
if !empty(a:cfile) && filereadable(a:cfile)
let val = readfile(a:cfile, 'b')
return eval(join(val, "\n"))
else
return {}
endif
endf
Jump to Line
Something went wrong with that request. Please try again.