# Transactional Cache

**URL:** <https://discuss.tryton.org/t/transactional-cache/1012>\
**Category:** Feature\
**Created:** [January 4, 2019, 5:39pm UTC](https://discuss.tryton.org/t/transactional-cache/1012 "2019-01-04T17:39:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [January 4, 2019, 5:39pm UTC](https://discuss.tryton.org/t/transactional-cache/1012/1 "2019-01-04T17:39:49Z")

</div>

## Rational

Currently the [Cache](http://docs.tryton.org/projects/server/en/latest/ref/cache.html#cache) is partially transactional. There are cases where it could be filled with wrong data:

- A transaction set some values which are not yet committed and if it fails to commit, those values stay in the cache.
- A transaction clear the cache and it is filled directly by another transaction with older data.

Those are rare cases because only mainly static data are cached. But this is not a reason to not improve the situation.

## Proposal

The idea is that modification of the Cache should be more “transactional” and reliable. A simple case is to allow to set in the cache only committed data. For that we could consider that a cache is always cleared when a transaction has modified the underlying data. So we should prevent a transaction that has cleared a cache to set data in it because those data will come from uncommitted transaction. Also in such case the cache should be empty only for the current transaction and cleared only when it is committed.  
So basically this means that the `get` and `set` methods will use a new LRUDict for transactions who have called `clear`. On transaction `commit`, the new cleared LRUDict will actually replace this others. And on transaction `rollback`, the new LRUDict will be destroyed.  
The `_nocache` attribute should prevent any usage of the Cache.

## Implementation

> **[Make Cache transactional (#7975) · Issues · Tryton / Tryton · GitLab](https://foss.heptapod.net/tryton/tryton/-/issues/7975)**
>
> From https://discuss.tryton.org/t/transactional-cache/1012

> **[Prevent older transaction to fill cache (#8019) · Issues · Tryton / Tryton ·...](https://foss.heptapod.net/tryton/tryton/-/issues/8019)**
>
> Following #7975, there are other cases where the cache could be...

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [February 1, 2019, 5:00pm UTC](https://discuss.tryton.org/t/transactional-cache/1012/2 "2019-02-01T17:00:06Z")

</div>

This topic was automatically closed after 14 days. New replies are no longer allowed.
