[GSoC 2023] swift-memcache-gsoc Project Kickoff

Hi, I’m Delkhaz (dkz) a computer science student based in Nashville,TN. This summer, I am thrilled to announce that I will be working on the development of a Memcached client using SwifttNIO (swift-memcache-gsoc) in collaboration with @FranzBusch, as part of the Google Summer of Code program. This project aims to develop a native Swift Memcached client using SwiftNIO to address the need for an efficient and user-friendly caching solution in Swift based applications.

Our ultimate objective is to deliver a high performance client that seamlessly integrates with exiting Swift ecosystems, streamlining the process of exchanging commands and receiving responses with memcached servers. By providing an asynchronous-first Swift API for essential memcached operations, this project aspires to empower developers to enhance their applications caching capabilities more effectively and efficiently.

Moreoever, the success of open source development relies on contribution. With that in mind, I wholeheartedly invite you, the community, to join me on this journey and actively participate in this project. You can do so by offering feedback, raising issues, or even contributing directly to the project in the future.

I also want to emphasize that this thread will serve as the primary means for updating the community on my progress as I start working on this project beginning on May 29th, 2023. I will be posting regular updates and eagerly invite everyone to provide their valuable feedback and insight.

Should you have any questions. Please don’t hesitate to ask them right here in this thread!

All the best



I've done something similar for Redis, feel free to use it as an inspiration. The protocol implementation is over here: swift-nio-redis, a client using it over here swift-nio-redis-client, and there is even a server redi/s.

1 Like

Hi @Helge_Hess1, Thats pretty cool I will definitely take a peek!
Thank you!

Thanks for the kickoff thread! Congrats on getting the project accepted and godspeed! :slight_smile:

Great plan to use the thread to keep folks posted, thanks for keeping that in mind! It's a big part of summer of code to get involved with others in the community, and not necessarily just your mentor :slight_smile: Thank you and godspeed!

1 Like

Hi everyone,

I have created the first few set of issues on GitHub that will not only serve as the starting roadmap for this project but also will provide an overview of the tasks I will be undertaking this summer. This is just the beginning and many more detailed issues will be added as we move forward.

Please consider these a glimpse into our plan for this summers GSoC project.

All the best



Hi Everyone,

I hope this message finds you well, I want to begin by expressing my profound gratitude to @FranzBusch, His mentorship has been invaluable in this project thus far and ive gained an enormous amount of knowledge during this summer GSoC experience. With each iteration of our API, Franz has challenged me to consistently strive for excellence in every facet of software development. He has also guided me through the intricacies of open source software, fostering in me a deep and comprehensive understanding. I am immensely thankful for his guidance and support.

I am excited to share with you the progress we have made on the development of our native Swift Memcached client over the past month. We have been working diligently and I am pleased to report the completion of several key issues that have set a robust foundation for the project.

  • Implementation of our MemcachedRequestEncoder and MemcachedRequest.

    • We’ve created an encoder handler capable of serializing a MemcachedRequest.
  • Implementation of our MemcachedResponseDecoder and MemcachedResponse.

    • We’ve created a decoder handler that can transform a ByteBuffer received from the Memcached server into a MemcachedResponse.
  • Get Request Implementation.

    • We’ve implemented a get request which includes response parsing to handle the values returned by the Memcahed server.
  • Set Request Implementation.

    • We’ve implemented a set request, allowing us to send a set command to the Memcached server.
  • Implementation of MemcachedFlag for Get Commands.

    • We defined and implemented our initial MemcahedFlags structure focusing specially on the v flag, which is essential for retrieving values associated with a given key.
  • Implementation of our MemcachedConnection actor that supports get and set operations.

    • We developed a basic actor that manages the connection lifecycle and allows interactions with the Memcached server.
  • Introduced MemcachedValue Protocol and Conformance.

    • We introduced a MemcachedValue protocol to manage the conversion of generic types to ByteBuffer, providing conformance for standard swift types, and the get and set methods in the actor were updated to use this new protocol, enchaining type safety and versatility of interactions with Memcached servers.

Now let’s take a deep dive into our actor:

Our MemcachedConnection allows for communicate with a Memcached. This actor takes care of establishing a connection, creating a request stream and handling asynchronous execution of commands. Here's an example of how you can use MemcachedConnection in a program.

import NIOCore
import NIOPosix
import SwiftMemcache

struct Program {
    static let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)

    static func main() async throws {
        // Create a new MemcachedConnection
        let memcachedConnection = MemcachedConnection(host: "", port: 11211, eventLoopGroup: eventLoopGroup)

        try await withThrowingTaskGroup(of: Void.self) { group in
            // Start the actor's run function
            group.addTask { try await memcachedConnection.run() }

            // Set a value for a key on the Memcached server
            let setValue = "bar"
            try await memcachedConnection.set("foo", value: setValue)

            // Fetch the value for a key from the Memcached server
            // Expected type for the value returned from Memcache is specified
            let getValue: String? = try await memcachedConnection.get("foo")

            // Check if the get operation was successful
            // If the values do not match, an error is thrown
            assert(getValue == setValue, "Value retrieved from Memcache does not match the set value")

            // Cancel all tasks in the task group, which also closes the connection to Memcache

While these achievements mark important milestones, we are far from finished. The road ahead includes further refining our API, incorporating more Memcached commands and functionalities, along with conducting more testing to ensure reliability and performance. You can track our progress and stay updated by monitoring the listed set of issues.

I encourage everyone to continue by providing feedback and raising issues. Your support and insights plays a critical role in shaping our progress and development. We look forward to your active participation and continued involvement.

I will continue to provide regular updates here. If you have any questions or concerns, feel free to post them in this thread.

Stay tuned for more exciting updates soon!

All the best



Hi Everyone,

To highlight things we starting this project with the goal of developing a native Swift Memcached client using SwiftNIO to address the need for an efficient and user-friendly caching solution in Swift based applications. The goal was to provide a high performance client that integrates seamlessly with existing Swift ecosystems, simplifying the process of sending commands and receiving responses from memcached servers. Our focus was on implementing the memcached meta protocol, request encoding, response decoding, and request pipelining, while the non-goals was to cover every memcached feature or command. We aimed to benefit developers by offering an asynchronous-first Swift API for essential memcached operations, ultimately enhancing the caching capabilities of their applications.

I'm excited to bring you up to speed on the next chapter of our native Swift Memcached client development. Over the past month, we’ve been working diligently and have successfully tackled another set of several key issues, further strengthening the project's foundation. This continues our ongoing efforts to keep you updated on our advancements.

  • Time-To-Live (TTL) Support: Added TTL support to the API, enabling users to set expiration for key-value pairs. This boosts cache efficiency and extends API capabilities.

  • Delete Operation Support: Integrated delete operation support, allowing direct removal of key-value pairs from cache. Enhances data control and versatility.

  • Append and Prepend Support: Introduced append and prepend support, enabling users to modify existing cache data directly. Improves cache efficiency and widens API versatility.

  • Add and Replace Support: Implemented add and replace support, enabling users to directly add and modify cache data. Enhances cache efficiency and API versatility.

  • Increment and Decrement Operations: Added support for increment and decrement operations, facilitating direct manipulation of numerical values in Memcached servers. Enhances caching strategies and data management efficiency.

  • Structured MemcachedError: Introduced structured MemcachedError to provide developers with better error understanding, leading to more efficient issue identification and resolution.

Ongoing Task:

  • Adapt Service Protocol: Currently adapting the Service protocol from swift-service-lifecycle for integration into MemcachedConnection.

  • Performance Benchmarking: Actively benchmarking MemcachedConnection for measuring performance metrics.

Upcoming Tasks:

  • Implement MemcachedClient: Enhance load balancing and resilient connection management for optimal cache key distribution across nodes. Strengthen the caching solution by improving handling of multiple nodes.

  • Adopt SwiftMetrics: Integrate SwiftMetrics for enhanced monitoring. Metrics to emit include request-response pairing and response time.

  • Partial Buffer Handling: Address current challenges in processing partial flags and buffers efficiently.

  • ASCII Integer Writing Performance: Improve the performance of ASCII integer writing into ByteBuffer.

As we wrap up this technical update, it's a bittersweet moment for me to share that my formal journey as a Google Summer of Code student has reached its conclusion, but what an incredible journey it's been. This transformative experience has enriched my understanding of open source development and honed my skills as a developer. I want to extend a heartfelt thank you to everyone who has been a part of this adventure with me.

While this chapter may be closing, I'm thrilled to announce that I will remain actively involved in the project. I'm particularly excited about contributing toward taking this project to its v1 or production stage. So, this isn't a goodbye; it's just the beginning of a new chapter. Looking forward to staying in touch and continuing this journey with all of you.

Special thanks are in order for @FranzBusch, for his exceptional mentorship during my time in the Google Summer of Code program. His wisdom and insights in our weekly sessions have been nothing short of transformative for me as a developer. Whether it was navigating the complexities of open-source contributions or striving for the highest standards in our API development, Franz’s guidance has been indispensable. I've gained a multifaceted understanding of software development thanks to his continued support. I couldn't have asked for a more impactful mentorship experience, and for that, I am deeply grateful.

All the best