Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds invalidate method to MemCacheMapping #10

Merged
merged 6 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()