Slide 98
Slide 98 text
Cache avec Redis
public protocol CacheService {
func load(for key: String) throws -> Node?
func save(node: Node, with key: String, expiration: TimeInterval) throws
}
public class RedisService : CacheService {
private let drop: Droplet
public init(drop: Droplet) throws {
try drop.addProvider(VaporRedis.Provider(config: drop.config))
self.drop = drop
}
public func load(for key: String) throws -> Node? {
return try drop.cache.get(key)
}
public func save(node: Node, with key: String, expiration: TimeInterval) throws {
try drop.cache.set(key, node)
if let redisCache = drop.cache as? RedisCache {
try redisCache.redbird.command("EXPIRE", params: [key, "\(Int(expiration))"])
}
}
}
98