CacheUtil.swift 1015 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //
  2. // CacheUtil.swift
  3. // CommonUtil
  4. //
  5. // Created by lijunjie on 15/12/4.
  6. // Copyright © 2015年 lijunjie. All rights reserved.
  7. //
  8. import Foundation
  9. public class CacheUtil {
  10. var cache: NSCache = NSCache<AnyObject, AnyObject>()
  11. static let share = CacheUtil()
  12. private init () {}
  13. public func shareCache() -> NSCache<AnyObject, AnyObject> {
  14. return cache
  15. }
  16. public func systemMemoryCacheSet(key: NSCoding, value: AnyObject) {
  17. self.shareCache().setObject(value, forKey: key)
  18. }
  19. public func systemMemoryCacheRemove(key: AnyObject) {
  20. self.shareCache().removeObject(forKey: key)
  21. }
  22. public func systemMemoryCacheGetValue(key:AnyObject) -> AnyObject? {
  23. return self.shareCache().object(forKey: key)
  24. }
  25. public func systemMemoryCacheEmptyValue(key:AnyObject) -> Bool {
  26. return (self.systemMemoryCacheGetValue(key: key) == nil)
  27. }
  28. }
  29. public let SharedCacheUtil: CacheUtil = CacheUtil.share