Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix Cache

  • Loading branch information...
commit 710fac6476ba75a30a82930b7f360360df09ed51 1 parent 9653a45
authored October 26, 2010
46  ftplugin/perl/perlomni.vim
@@ -67,22 +67,48 @@ endf
67 67
 
68 68
 " Cache Function. {{{
69 69
 let s:last_cache_ts = localtime()
  70
+let s:cache_expiry =  { }
  71
+let s:cache_last   =  { }
  72
+
70 73
 fun! GetCacheNS(ns,key)
71  
-    if localtime() - s:last_cache_ts > g:perlomni_cache_expiry
72  
-        let s:last_cache_ts = localtime()
  74
+    let key = a:ns . "_" . a:key
  75
+    if has_key( s:cache_expiry , key ) 
  76
+        let expiry = s:cache_expiry[ key ]
  77
+        let last_ts = s:cache_last[ key ]
  78
+    else 
  79
+        let expiry = g:perlomni_cache_expiry
  80
+        let last_ts = s:last_cache_ts
  81
+    endif
  82
+
  83
+    if localtime() - last_ts > expiry
  84
+        if has_key( s:cache_expiry , key ) 
  85
+            let s:cache_last[ key ] = localtime()
  86
+        else
  87
+            let s:last_cache_ts = localtime()
  88
+        endif
73 89
         return 0
74 90
     endif
75 91
 
76 92
     if ! g:perlomni_use_cache
77 93
         return 0
78 94
     endif
79  
-    let key = a:ns . "_" . a:key
80 95
     if exists('g:perlomni_cache[key]')
81 96
         return g:perlomni_cache[key]
82 97
     endif
83 98
     return 0
84 99
 endf
85 100
 
  101
+fun! SetCacheNSWithExpiry(ns,key,value,exp)
  102
+    if ! exists('g:perlomni_cache')
  103
+        let g:perlomni_cache = { }
  104
+    endif
  105
+    let key = a:ns . "_" . a:key
  106
+    let g:perlomni_cache[ key ] = a:value
  107
+    let s:cache_expiry[ key ] = a:exp
  108
+    let s:cache_last[ key ] = localtime()
  109
+    return a:value
  110
+endf
  111
+
86 112
 fun! SetCacheNS(ns,key,value)
87 113
     if ! exists('g:perlomni_cache')
88 114
         let g:perlomni_cache = { }
@@ -458,7 +484,6 @@ fun! s:CompFunction(base,context)
458 484
     let flist = copy(g:p5bfunctions)
459 485
     cal extend(flist,efuncs)
460 486
     return filter(flist,'v:val.word =~ "^".a:base')
461  
-    " return s:StringFilter(g:p5bfunctions,a:base)
462 487
 endf
463 488
 
464 489
 fun! s:CompCurrentBaseFunction(base,context)
@@ -745,7 +770,7 @@ fun! s:scanCurrentExportFunction()
745 770
     endif
746 771
 
747 772
     let lines = getline( 1 , '$' )
748  
-    cal filter(  lines , 'v:val =~ ''^\s*use\s''')
  773
+    cal filter(  lines , 'v:val =~ ''^\s*\(use\|require\)\s''')
749 774
     let funcs = [ ]
750 775
     for line in lines
751 776
         let m = matchstr( line , '\(^use\s\+\)\@<=' . s:mod_pattern )
@@ -796,7 +821,7 @@ endf
796 821
 " }}}
797 822
 
798 823
 fun! s:scanObjectVariableFile(file)
799  
-"     let l:cache = GetCacheNS('objvar_', a:file)
  824
+"     let l:cache = GetCacheNS('objvar', a:file)
800 825
 "     if type(l:cache) != type(0)
801 826
 "         return l:cache
802 827
 "     endif
@@ -812,11 +837,13 @@ fun! s:scanObjectVariableFile(file)
812 837
         endif
813 838
     endfor
814 839
     return b:objvarMapping
815  
-"     return SetCacheNS('objvar_',a:file,b:objvarMapping)
  840
+"     return SetCacheNSWithExpiry('objvar',a:file,b:objvarMapping,60 * 10)
816 841
 endf
817 842
 " echo s:scanObjectVariableFile( expand('~/git/bps/jifty-dbi/lib/Jifty/DBI/Collection.pm') )
818 843
 
819 844
 
  845
+
  846
+" XXX: CACHE THIS
820 847
 fun! s:scanHashVariable(lines)
821 848
     let buffile = tempname()
822 849
     cal writefile(a:lines,buffile)
@@ -825,6 +852,7 @@ endf
825 852
 " echo s:scanHashVariable( getline(1,'$') )
826 853
 
827 854
 
  855
+" XXX: CACHE THIS
828 856
 fun! s:scanQString(lines)
829 857
     let buffile = tempname()
830 858
     cal writefile( a:lines, buffile)
@@ -832,6 +860,7 @@ fun! s:scanQString(lines)
832 860
     return split( cmd ,"\n")
833 861
 endf
834 862
 
  863
+" XXX: CACHE THIS
835 864
 fun! s:scanQQString(lines)
836 865
     let buffile = tempname()
837 866
     cal writefile( a:lines, buffile)
@@ -839,6 +868,9 @@ fun! s:scanQQString(lines)
839 868
 endf
840 869
 " echo s:scanQQStringFile('testfile')
841 870
 
  871
+
  872
+
  873
+" XXX: CACHE THIS
842 874
 fun! s:scanArrayVariable(lines)
843 875
     let buffile = tempname()
844 876
     cal writefile(a:lines,buffile)
4  test-case/01-base-class-methods.pm
@@ -2,8 +2,6 @@ package Test;
2 2
 use base qw(App::CLI);
3 3
 
4 4
 # complete here
5  
-sub a
6  
-
7  
-
  5
+# sub a
8 6
 
9 7
 1;
10  test-case/03-obj-methods.pm
@@ -3,22 +3,20 @@
3 3
 
4 4
 
5 5
 my $obj = new Jifty::Web;
6  
-$obj->
  6
+$obj->caller
7 7
 
8 8
 my $var = new Jifty;
9  
-$var->
  9
+$var->app_instance_id
10 10
 
11 11
 
12 12
 my $cgi = new CGI;
13 13
 print $cgi->
14 14
 
15 15
 my $cgi2 = CGI->new;
16  
-$cgi2->append
17  
-
18  
-
19  
-
  16
+$cgi2->
20 17
 
21 18
 # complete class methods
22 19
 Jifty::DBI::Record->__create
23 20
 Jifty->
24 21
 Moose->
  22
+Catalyst::Action->code
5  test-case/06-moose.pm
... ...
@@ -1,17 +1,14 @@
1 1
 
2 2
 # moose complete
3  
-
4 3
 has url => (
5 4
     metaclass => 'Labeled',
6 5
     is => 'wo'
7 6
     label     => "The site's URL",
8 7
     isa => 'AFS::Object',
9  
-    reader => 'url
10  
-    writer => '
  8
+    reader => 
11 9
 );
12 10
 
13 11
 # role
14  
-
15 12
 with 'Restartable' => {
16 13
     -alias => {
17 14
         stop  => '_stop',
2  test-case/07-export-function.pl
@@ -11,6 +11,6 @@
11 11
 
12 12
 # a to all
13 13
 
14  
-m
  14
+min
15 15
 
16 16
 # m to max

0 notes on commit 710fac6

Please sign in to comment.
Something went wrong with that request. Please try again.