# Logstash Cache

**URL:** https://discuss.elastic.co/t/logstash-cache/241202
**Category:** Logstash
**Created:** [July 14, 2020, 10:14pm UTC](https://discuss.elastic.co/t/logstash-cache/241202 "2020-07-14T22:14:21Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![csgeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/csgeek/32/72144_2.png) [@csgeek](https://discuss.elastic.co/u/csgeek)
#### Post date: [July 14, 2020, 10:14pm UTC](https://discuss.elastic.co/t/logstash-cache/241202/1 "2020-07-14T22:14:21Z")

</div>

I'm working on an event filter written in ruby that needs to do a lookup.

I have the data stored in a JSON file that i'm loading locally and I'd like to know if there is any concept of a shared cache that I can leverage to avoid reading a file each time, parsing it in order to do a single lookup each time.

Ideally I would rather avoid adding a redis or memcache layer, though I suppose that is an option.

Any suggestions?

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [July 14, 2020, 10:18pm UTC](https://discuss.elastic.co/t/logstash-cache/241202/2 "2020-07-14T22:18:20Z")

</div>

That sounds like you are re-implementing the translate filter. If translate is not a match for your use case you can still harvest the dictionary loading and reloading [code from it](https://github.com/logstash-plugins/logstash-filter-translate/tree/master/lib/logstash/filters).

Or else just load the file into an @instance variable in the init section of the filter.

---

<div class="post-metadata">

### Author: ![csgeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/csgeek/32/72144_2.png) [@csgeek](https://discuss.elastic.co/u/csgeek)
#### Post date: [July 14, 2020, 10:21pm UTC](https://discuss.elastic.co/t/logstash-cache/241202/3 "2020-07-14T22:21:49Z")

</div>

I was actually thinking about that a second after posting it. I can just remove the code from the ruby filter and let translate take care of it.

Sorry about that, but thank you for the help.

I think the translate works a bit different since it's an actual plugin that a ruby filter that executes some arbitrary code. Still good reference to look at.

---

<div class="post-metadata">

### Author: ![csgeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/csgeek/32/72144_2.png) [@csgeek](https://discuss.elastic.co/u/csgeek)
#### Post date: [July 14, 2020, 10:28pm UTC](https://discuss.elastic.co/t/logstash-cache/241202/4 "2020-07-14T22:28:18Z")

</div>

> [@Badger](#):
>
> Or else just load the file into an @instance variable in the init section of the filter.

if I load the data in a @instance will it not be re-loaded again for each event? is that a one time operation?

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [July 14, 2020, 10:34pm UTC](https://discuss.elastic.co/t/logstash-cache/241202/5 "2020-07-14T22:34:58Z")

</div>

The code in the init option of a ruby filter is one and done when the pipeline starts. The code in the code option is per-event.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [August 11, 2020, 10:35pm UTC](https://discuss.elastic.co/t/logstash-cache/241202/6 "2020-08-11T22:35:12Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
