mirror of
https://github.com/gwenhael-le-moine/credger.git
synced 2024-12-26 09:58:36 +01:00
memoization
This commit is contained in:
parent
b031127e9c
commit
140ec7f9d5
1 changed files with 10 additions and 2 deletions
12
ledger.cr
12
ledger.cr
|
@ -7,11 +7,19 @@ class Ledger
|
|||
ledger_file : String = ENV[ "LEDGER_FILE" ] ||= "${ENV[ \"HOME\" ]}/org/comptes.ledger" )
|
||||
@binary = binary
|
||||
@file = ledger_file
|
||||
|
||||
@cache = Hash(String, String).new
|
||||
end
|
||||
|
||||
def run( options : String, command : String = "", command_parameters : String = "" ) : String
|
||||
STDERR.puts "#{@binary} -f #{@file} #{options} #{command} #{command_parameters}"
|
||||
`#{@binary} -f #{@file} #{options} #{command} #{command_parameters}`
|
||||
command = "#{@binary} -f #{@file} #{options} #{command} #{command_parameters}"
|
||||
STDERR.puts command
|
||||
|
||||
mtime = File.info(@file).modification_time
|
||||
key = "#{mtime}#{command}"
|
||||
@cache[ key ] = `#{command}` unless @cache.has_key?( key )
|
||||
|
||||
@cache[ key ]
|
||||
end
|
||||
|
||||
def version : String
|
||||
|
|
Loading…
Reference in a new issue