Skip to content

Using Caching in LUA transform #8134

Answered by jszwedko
atibdialpad asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @atibdialpad !

Yeah, the runtime will persist across events so you can do caching like that. I'd suggest rewriting this a bit to something like:

[transforms.lua]
type = "lua"
inputs = []
version = "2"

hooks.process = "process"

source = '''
  cache = {}
  function get(key)
    if not cache[key] then
      cache[key] = <make a http call here to populate the cache>
    end
    return cache[key]
  end

  function process(event, emit)
    if event.log.interface_name then
      event.log.interface_description = get(interface_name)
    end
  end
'''

You could also use the timer mechanism to clear the cache on an interval.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@atibdialpad
Comment options

@atibdialpad
Comment options

@jszwedko
Comment options

Answer selected by atibdialpad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants