# Native Filter Scripts + Caching may be broken

**URL:** <https://discuss.elastic.co/t/native-filter-scripts-caching-may-be-broken/2356>\
**Category:** Elasticsearch\
**Created:** [June 10, 2015, 4:42pm UTC](https://discuss.elastic.co/t/native-filter-scripts-caching-may-be-broken/2356 "2015-06-10T16:42:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Chambers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matt_chambers/32/607_2.png) [@Matt\_Chambers](https://discuss.elastic.co/u/Matt_Chambers)\
**Post date:** [June 10, 2015, 4:42pm UTC](https://discuss.elastic.co/t/native-filter-scripts-caching-may-be-broken/2356/1 "2015-06-10T16:42:28Z")

</div>

Version 1.5.2

I wrote a native filter script for Elastic and I noticed that a new instance of the script is created for every document returned.

FilterBuilders().scriptFilter("aclscript").lang("native").cache(true).cacheKey(AuthUtils.getUsername())

I assumed that cache=true would cache the instance of the script created by the factory, but I guess I was wrong. I can put my own caching in the factory but I figured I'd check and see if this was the intended behavior or cache=true.

---

<div class="post-metadata">

**Author:** ![Matt\_Chambers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matt_chambers/32/607_2.png) [@Matt\_Chambers](https://discuss.elastic.co/u/Matt_Chambers)\
**Post date:** [June 10, 2015, 5:58pm UTC](https://discuss.elastic.co/t/native-filter-scripts-caching-may-be-broken/2356/2 "2015-06-10T17:58:42Z")

</div>

Actually, looks like one instance is created per thread which is better than what I thought it was doing. I needed more results in my test.

So i guess cache must hold onto those instances between searches. Would be great to have a way to time the cache out.

---

<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:** [July 6, 2017, 12:08am UTC](https://discuss.elastic.co/t/native-filter-scripts-caching-may-be-broken/2356/3 "2017-07-06T00:08:31Z")

</div>


