# Need to force inventory cache usage past timeout

**URL:** <https://forum.ansible.com/t/need-to-force-inventory-cache-usage-past-timeout/33398>\
**Category:** Ansible Developer\
**Created:** [July 14, 2020, 11:21pm UTC](https://forum.ansible.com/t/need-to-force-inventory-cache-usage-past-timeout/33398 "2020-07-14T23:21:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![opoplawski](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/opoplawski/32/2112_2.png) [@opoplawski](https://forum.ansible.com/u/opoplawski)\
**Post date:** [July 14, 2020, 11:21pm UTC](https://forum.ansible.com/t/need-to-force-inventory-cache-usage-past-timeout/33398/1 "2020-07-14T23:21:17Z")

</div>

I’m working on converting the old cobbler inventory script to an inventory plugin. See [https://github.com/ansible-collections/community.general/pull/627](https://github.com/ansible-collections/community.general/pull/627)

The behavior that I last had with my last version of the inventory script was for it to fall back to the cached data regardless of the time since last update if it could not contact the cobbler server. This allows for ansible-pull to work off of our internal network. However, with the use of cache plugins (jsonfile in my case) I do not see a way to achieve this. Any suggestions?

---

<div class="post-metadata">

**Author:** ![opoplawski](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/opoplawski/32/2112_2.png) [@opoplawski](https://forum.ansible.com/u/opoplawski)\
**Post date:** [July 15, 2020, 3:14pm UTC](https://forum.ansible.com/t/need-to-force-inventory-cache-usage-past-timeout/33398/2 "2020-07-15T15:14:25Z")

</div>

This is what I've come up with:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.\_options['cache\_timeout'] = 0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.load\_cache\_plugin()  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.\_cache.get(self.cache\_key, {})

seems to work.

---

<div class="post-metadata">

**Author:** ![opoplawski](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/opoplawski/32/2112_2.png) [@opoplawski](https://forum.ansible.com/u/opoplawski)\
**Post date:** [July 16, 2020, 10:52pm UTC](https://forum.ansible.com/t/need-to-force-inventory-cache-usage-past-timeout/33398/3 "2020-07-16T22:52:27Z")

</div>

Well, not quite. Due to the bug mentioned below I ended up with:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Work around [https://github.com/ansible/ansible/issues/70702](https://github.com/ansible/ansible/issues/70702)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.\_options['cache\_timeout'] = sys.maxsize
