Skip to content

Commit

Permalink
Merge pull request #10 from rber474/master
Browse files Browse the repository at this point in the history
 Adds invalidate method to MemCacheMapping
  • Loading branch information
dataflake authored Oct 3, 2023
2 parents 8883772 + d70c2d8 commit 214aa68
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Change log
4.1 (unreleased)
----------------

- Adds invalidate method to MemCacheMapping and test

4.0 (2023-02-02)
----------------
Expand Down
10 changes: 10 additions & 0 deletions src/Products/mcdutils/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ def commit(self, txn):
""" See IDataManager.
"""

security.declarePrivate('invalidate') # NOQA: D001

def invalidate(self):
""" See TransientObject.
"""
try:
self._p_proxy.delete(self._p_key)
except KeyError:
pass

security.declarePrivate('tpc_vote') # NOQA: D001

def tpc_vote(self, txn):
Expand Down
19 changes: 19 additions & 0 deletions src/Products/mcdutils/tests/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ def test_repr(self):
self.assertIn("'%s': '<password obscured>'" % pw_key, mapping_repr)
self.assertIn("'normal': 'normalvalue'", mapping_repr)

def test_invalidate(self):
"""Tests invalidate method"""
proxy = DummyProxy()
proxy._set('key', 'myvalue')
mapping = self._makeOne('key', proxy)

self.assertIn('key', proxy._cached)
mapping.invalidate()
self.assertNotIn('key', proxy._cached)

# Cleaning again won't throw errors
self.assertIsNone(mapping.invalidate())


class DummyClient:
def _get_server(self, key):
Expand All @@ -146,4 +159,10 @@ def _clean(self, key):
except KeyError:
pass

def delete(self, key):
try:
del self._cached[key]
except KeyError:
pass

client = DummyClient()

0 comments on commit 214aa68

Please sign in to comment.