Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 25, 2025

This PR adds a complete MemcachedStore implementation to the KV Store Adapter, providing high-performance distributed caching capabilities through the pymemcache client.

Implementation Details

The MemcachedStore extends BaseManagedKVStore and provides full async support with the following key features:

  • Native TTL Support: Leverages memcached's built-in expiration mechanism
  • Key Length Handling: Automatically hashes keys exceeding memcached's 250-character limit using MD5
  • Flexible Initialization: Supports both direct connection parameters and existing pymemcache client instances
  • Robust Error Handling: Proper connection testing and StoreConnectionError integration

Usage Examples

from kv_store_adapter.stores.memcached import MemcachedStore

# Connection with host and port
store = MemcachedStore(host="localhost", port=11211)

# Using existing pymemcache client
from pymemcache.client.base import Client
client = Client(("localhost", 11211))
store = MemcachedStore(client=client)

# Standard KV operations with TTL support
await store.put("collection", "key", {"data": "value"}, ttl=3600)
result = await store.get("collection", "key")

Memcached Limitations

Due to memcached's architecture, certain operations have inherent limitations that are transparently handled:

  • keys(), clear_collection(), and list_collections() return empty results since memcached doesn't support key enumeration
  • Keys longer than 250 characters are automatically hashed to ensure compatibility
  • These limitations are clearly documented in both code and user documentation

Dependencies and Integration

  • Added pymemcache>=4.0.0 as an optional dependency in pyproject.toml
  • Updated documentation in both README.md and DEVELOPING.md
  • Comprehensive test suite with proper CI integration using @pytest.mark.skip_on_ci
  • All code passes linting with proper type safety and style compliance

Testing

The implementation includes extensive tests covering:

  • Basic store operations and initialization patterns
  • Long key handling and automatic hashing
  • TTL functionality and expiration behavior
  • Connection error handling and recovery
  • Memcached-specific limitations and edge cases

This adds memcached as a production-ready store option alongside Redis, Elasticsearch, and other existing implementations, providing users with another high-performance caching solution for distributed environments.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add memcached store</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #6

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits September 25, 2025 02:14
Co-authored-by: strawgate <6384545+strawgate@users.noreply.github.com>
Co-authored-by: strawgate <6384545+strawgate@users.noreply.github.com>
Copilot AI changed the title [WIP] Add memcached store Add memcached store implementation Sep 25, 2025
Copilot AI requested a review from strawgate September 25, 2025 02:20
Copilot finished work on behalf of strawgate September 25, 2025 02:20
@strawgate strawgate closed this Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add memcached store

2 participants