# Inventory Plugin cache is not being flushed in Ansible 2.7 anymore

**URL:** <https://forum.ansible.com/t/inventory-plugin-cache-is-not-being-flushed-in-ansible-2-7-anymore/31709>\
**Category:** Ansible Developer\
**Created:** [November 22, 2019, 2:59pm UTC](https://forum.ansible.com/t/inventory-plugin-cache-is-not-being-flushed-in-ansible-2-7-anymore/31709 "2019-11-22T14:59:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Philip\_Douglass](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@Philip\_Douglass](https://forum.ansible.com/u/Philip_Douglass)\
**Post date:** [November 22, 2019, 2:59pm UTC](https://forum.ansible.com/t/inventory-plugin-cache-is-not-being-flushed-in-ansible-2-7-anymore/31709/1 "2019-11-22T14:59:06Z")

</div>

Due to the following deprecation warnings:

[DEPRECATION WARNING]: InventoryModule should utilize self.\_cache as a dict instead of self.cache. When expecting a KeyError, use self.\_cache[key] instead of using self.cache.get(key). self.\_cache is a dictionary and will return a default value instead of raising a KeyError when the key does not exist. This feature will be removed in version 2.12.

[DEPRECATION WARNING]: InventoryModule should utilize self.\_cache as a dict instead of self.cache. To set the self.\_cache dictionary, use self.\_cache[key] = value instead of self.cache.set(key, value). To force update the underlying cache plugin with the contents of self.\_cache before parse() is complete, call self.set\_cache\_plugin and it will use the self.\_cache dictionary to update the cache plugin. This feature will be removed in version 2.12.

I’ve updated my custom inventory plugins:

`  
def \_fetch(self, url):  
cache\_key = self.get\_cache\_key(url)

if self.attempt\_to\_read\_cache:  
try:

# return self.cache.get(cache\_key) # Old stable-2.7 method

return self.\_cache[cache\_key] # New stable-2.8+ method  
except KeyError:  
display.debug(“cache miss”)  
self.cache\_needs\_update = True

results = self.\_process\_url(url)

if self.cache\_needs\_update:

# self.cache.set(cache\_key, results) # Old stable-2.7 method

self.\_cache[cache\_key] = results # New stable-2.8+ method (not working in stable-2.7!)

return results

`

However, when running this with Ansible 2.7, the cache doesn’t get flushed to disk, so each attempt to read the cache results in a cache miss. Is there any way to make this backwards compatible with Ansible 2.7 without causing a DeprecationWarning?
