Swiftpack.co -  Package - m-barthelemy/VaporLRUMemoryCache
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
LRU in-memory cache for Vapor4
.package(url: "https://github.com/m-barthelemy/VaporLRUMemoryCache.git", from: "0.1.0")


This is a library providing an LRU Cache for Vapor4.

Like the default Memory cache provided by Vapor, it caches content in memory and doesn't have any dependency.

However, VaporLRUMemoryCache has a fixed capacity. When it is reached, least recently accessed items will be deleted. In that sense, this cache is self-maintaining.

The underlying LRU implementation if fairly basic and not optimal; it will probably be improved in the future, but does the job quite well in the meantime.


Add the package to your Vapor4 project:

    dependencies: [
        .package(url: "https://github.com/m-barthelemy/VaporLRUMemoryCache.git", from: "0.1.0"),
    targets: [
        .target(name: "App", dependencies: [

Configure Vapor to use VaporLRUMemoryCache. This has to be added with the rest of your Vapor4 configuration; usually configure.swift :

import VaporLRUMemoryCache

public func configure(_ app: Application) throws {

Then, use it! For example, from any Vapor controller:

func get(req: Request) -> EventLoopFuture<MyStuff> {
    return req.cache.get("mystuff-cache-key", as: MyStuff.self)
        .unwrap(or: Abort(.notFound))
        .map { $0}


Stars: 0
Last commit: 4 weeks ago


Release Notes

Working implementation
4 weeks ago

This release contains a working implementation. It is sub-optimal, performance and memory-wise, and doesn't have any unit tests yet.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco