zoukankan      html  css  js  c++  java
  • 缓存

    http://www.jianshu.com/p/ce5e7427e740

    自定义设置时间戳缓存

     static func set<T>(key: String, value: T, timeout: Double = 0) {

            objc_sync_enter(lock)

            let saveValue: [String: Any] = [

                "saveTime" : timeout == 0 ? 0 : NSDate().timeIntervalSince1970 + timeout,

                "data" : value

            ]

            self.value[key] = saveValue

            objc_sync_exit(lock)

        }

        

        static func get<T>(key: String) -> T? {

            objc_sync_enter(lock)

            let t = _T<[String: Any]>.cast(self.value[key])

            if t != nil {

                let cacheTime = (t!["saveTime"] ?? 0) as! Double

                if cacheTime > 0 && NSDate().timeIntervalSince1970 > cacheTime {

                    self.value.removeValueForKey(key)

                }

            } else {

                return nil

            }

            objc_sync_exit(lock)

            return t!["data"] as? T

        }

  • 相关阅读:
    交流课件
    ARC127F ±AB
    CF1566F xor-quiz
    JOISC 2016 Day 1 棋盘游戏
    dev分支和release是什么
    drf 笔记
    drf 序列化的写法 总结
    Linux系统编程
    C/C++ 网络编程
    C++提高编程
  • 原文地址:https://www.cnblogs.com/hazhede/p/5529951.html
Copyright © 2011-2022 走看看