Skip to content
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
2 changes: 2 additions & 0 deletions src/zeroconf/_services/info.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,5 @@ cdef class ServiceInfo(RecordUpdateListener):

@cython.locals(cacheable=cython.bint)
cdef cython.set _get_address_and_nsec_records(self, object override_ttl)

cpdef async_clear_cache(self)
8 changes: 8 additions & 0 deletions src/zeroconf/_services/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ def properties(self) -> Dict[Union[str, bytes], Optional[Union[str, bytes]]]:
assert self._properties is not None
return self._properties

def async_clear_cache(self) -> None:
"""Clear the cache for this service info."""
self._dns_address_cache = None
self._dns_pointer_cache = None
self._dns_service_cache = None
self._dns_text_cache = None
self._get_address_and_nsec_records_cache = None

async def async_wait(self, timeout: float, loop: Optional[asyncio.AbstractEventLoop] = None) -> None:
"""Calling task waits for a given number of milliseconds or until notified."""
if not self._new_records_futures:
Expand Down
1 change: 1 addition & 0 deletions src/zeroconf/_services/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def _add(self, info: ServiceInfo) -> None:
if info.key in self._services:
raise ServiceNameAlreadyRegistered

info.async_clear_cache()
self._services[info.key] = info
self.types.setdefault(info.type.lower(), []).append(info.key)
self.servers.setdefault(info.server_key, []).append(info.key)
Expand Down
7 changes: 7 additions & 0 deletions tests/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,20 @@ def update_service(self, zeroconf: Zeroconf, type: str, name: str) -> None:
)
task = await aiozc.async_update_service(new_info)
await task
assert new_info.dns_service().server_key == "ash-2.local."
new_info.server = "ash-3.local."
task = await aiozc.async_update_service(new_info)
await task
assert new_info.dns_service().server_key == "ash-3.local."

task = await aiozc.async_unregister_service(new_info)
await task
await aiozc.async_close()

assert calls == [
('add', type_, registration_name),
('update', type_, registration_name),
('update', type_, registration_name),
('remove', type_, registration_name),
]

Expand Down