| 60 | } |
| 61 | |
| 62 | func (s *Stash) Compile(logger *log.Entry) (*RuntimeStash, error) { |
| 63 | var err error |
| 64 | |
| 65 | rs := &RuntimeStash{Config: s} |
| 66 | |
| 67 | rs.ValueExpression, err = expr.Compile(s.Value, |
| 68 | exprhelpers.GetExprOptions(map[string]any{"evt": &pipeline.Event{}})...) |
| 69 | if err != nil { |
| 70 | return nil, fmt.Errorf("while compiling stash value expression: %w", err) |
| 71 | } |
| 72 | |
| 73 | rs.KeyExpression, err = expr.Compile(s.Key, |
| 74 | exprhelpers.GetExprOptions(map[string]any{"evt": &pipeline.Event{}})...) |
| 75 | if err != nil { |
| 76 | return nil, fmt.Errorf("while compiling stash key expression: %w", err) |
| 77 | } |
| 78 | |
| 79 | rs.TTLVal, err = time.ParseDuration(s.TTL) |
| 80 | if err != nil { |
| 81 | return nil, fmt.Errorf("while parsing stash ttl: %w", err) |
| 82 | } |
| 83 | |
| 84 | // init the cache, does it make sense to create it here just to be sure everything is fine ? |
| 85 | |
| 86 | cacheCfg := cache.CacheCfg{ |
| 87 | Size: s.MaxMapSize, |
| 88 | TTL: rs.TTLVal, |
| 89 | Name: s.Name, |
| 90 | Strategy: s.Strategy, |
| 91 | LogLevel: logger.Logger.GetLevel(), |
| 92 | } |
| 93 | |
| 94 | if err = cache.CacheInit(cacheCfg, cacheCfg.NewLogger()); err != nil { |
| 95 | return nil, fmt.Errorf("while initializing cache: %w", err) |
| 96 | } |
| 97 | |
| 98 | return rs, nil |
| 99 | } |
| 100 | |
| 101 | func (rs *RuntimeStash) Apply(idx int, cachedExprEnv map[string]any, logger *log.Entry, debug bool) { |
| 102 | var ( |