huynguyencong / datacache Goto Github PK
View Code? Open in Web Editor NEWSimple disk and memory cache for iOS
License: MIT License
Simple disk and memory cache for iOS
License: MIT License
@huynguyencong
There warnings in xcode 8.3
let resourceValues = try URL.resourceValues(forKeys: Set(resourceKeys), fromBookmarkData: bookmarkData)?.allValues
//No calls to throwing functions with try expression
I have the issue to clean the cache. I am curious if the is completion block for cache expire that automatically called so I should be able to know that it is a time to go for server to fetch the fresh one.
Is it possible to remove from the cache?
For my usecase, when I remove an object from my server storage, my device is notified at which point i want to remove the file from memory.
i tried this but it didnt work
func applicationWillTerminate(_ application: UIApplication) {
DataCache.instance.cleanAll()
}
not just cleanAll method
i tried with all clean method but it didn't work
Hello, I noticed your example of reading images is out of date. Someone change the method readImage to readImageFromKey.
Your docs read
let image = DataCache.instance.readImage(forKey: "imageKey")
Should read
let image = DataCache.instance.readImageForKey(key: "imageKey")
Otherwise really enjoying the framework, thanks! ๐ค
Hey, I have changes for Swift 3. Do you want to create a new branch or should I pull to either develop or directly to the master branch?
The changes are 90% compliant except two things related to unSafePointers
Is it possible to update UIKit part conditionally with AppKit to make this package work on macOS projects too?
I would like to ask how the disk memory cache is being implemented. Is it via UserDefaults? Thanks
Hello,
since the update to iOS 11 I am getting a lot of crashes involving DataCache. Here is two crash reports:
Thread 5 Crashed:
0 libswiftCore.dylib 0x0000000103065e5c 0x102d78000 + 3071580
1 libswiftCore.dylib 0x0000000103065e90 0x102d78000 + 3071632
2 DataCache 0x0000000102ac697c specialized closure #1 in DataCache.cleanExpiredDiskCacheWithCompletionHander(completionHandler:) (DataCache.swift:0)
3 DataCache 0x0000000102ac5c4c partial apply for closure #1 in DataCache.cleanExpiredDiskCacheWithCompletionHander(completionHandler:) (DataCache.swift:0)
4 DataCache 0x0000000102ac117c thunk for @callee_owned () -> () (DataCache.swift:0)
5 libdispatch.dylib 0x0000000183ced088 _dispatch_call_block_and_release + 20
6 libdispatch.dylib 0x0000000183ced048 _dispatch_client_callout + 12
7 libdispatch.dylib 0x0000000183cf6e48 _dispatch_queue_serial_drain$VARIANT$mp + 524
8 libdispatch.dylib 0x0000000183cf77d8 _dispatch_queue_invoke$VARIANT$mp + 336
9 libdispatch.dylib 0x0000000183cf8200 _dispatch_root_queue_drain_deferred_wlh$VARIANT$mp + 396
10 libdispatch.dylib 0x0000000183d004a0 _dispatch_workloop_worker_thread$VARIANT$mp + 640
11 libsystem_pthread.dylib 0x0000000183f92fe0 _pthread_wqthread + 928
12 libsystem_pthread.dylib 0x0000000183f92c30 start_wqthread + 0\
Thread 3 Crashed:
0 libsystem_platform.dylib 0x00000001809ce8f8 OSAtomicDequeue$VARIANT$mp + 12
1 libsystem_malloc.dylib 0x0000000180908c1c _nano_malloc_check_clear + 148
2 libsystem_malloc.dylib 0x0000000180907ce0 nano_calloc + 76
3 libsystem_malloc.dylib 0x00000001808f94f0 malloc_zone_calloc + 164
4 libsystem_malloc.dylib 0x00000001808f9424 calloc + 36
5 libobjc.A.dylib 0x00000001802c1238 realizeClass(objc_class*) + 72
6 libobjc.A.dylib 0x00000001802bee9c _class_getNonMetaClass + 136
7 libobjc.A.dylib 0x00000001802c5740 lookUpImpOrForward + 220
8 libobjc.A.dylib 0x00000001802d0758 _objc_msgSend_uncached + 52
9 FileProvider 0x000000018836f870 FPBookmarkableStringFromDocumentURL + 124
10 CoreServicesInternal 0x00000001a2661f6c createBookmarkWithURLAtDepth(__CFAllocator const*, __CFURL const*, unsigned long, __CFURL const*, __CFArray const*, BookmarkMutableData&, unsigned int, bool, __CFError**) + 328
11 CoreServicesInternal 0x00000001a2661ddc _CFURLCreateBookmarkData + 240
12 CoreFoundation 0x0000000180ddd204 -[NSURL bookmarkDataWithOptions:includingResourceValuesForKeys:relativeToURL:error:] + 240
13 libswiftFoundation.dylib 0x0000000101d5b024 0x101cac000 + 716836
14 DataCache 0x000000010155e8a0 specialized closure #1 in DataCache.cleanExpiredDiskCacheWithCompletionHander(completionHandler:) (DataCache.swift:302)15 DataCache 0x000000010155dc4c partial apply for closure #1 in DataCache.cleanExpiredDiskCacheWithCompletionHander(completionHandler:) (DataCache.swift:0)16 DataCache 0x000000010155917c thunk for @callee_owned () -> () (DataCache.swift:0)17 libdispatch.dylib 0x000000018072d088 _dispatch_call_block_and_release + 20
18 libdispatch.dylib 0x000000018072d048 _dispatch_client_callout + 12
19 libdispatch.dylib 0x0000000180736e48 _dispatch_queue_serial_drain$VARIANT$mp + 524
20 libdispatch.dylib 0x00000001807377d8 _dispatch_queue_invoke$VARIANT$mp + 336
21 libdispatch.dylib 0x0000000180738200 _dispatch_root_queue_drain_deferred_wlh$VARIANT$mp + 396
22 libdispatch.dylib 0x00000001807404a0 _dispatch_workloop_worker_thread$VARIANT$mp + 640
23 libsystem_pthread.dylib 0x00000001809d2fe0 _pthread_wqthread + 928
24 libsystem_pthread.dylib 0x00000001809d2c30 start_wqthread + 0
Any idea what is causing this and how it can be resolved? Let me know if you need more info from me.
I noticed when I run my cached NSData through a decoder, it just freezes the app. Decoding works if it comes from the source directly.
func decodeEncodedString() -> String? {
let encodedData = self.dataUsingEncoding(NSUTF8StringEncoding)!
let attributedOptions : [String: AnyObject] = [
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding
]
do {
let attributedString = try NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil)
return attributedString.string
} catch let error as NSError {
// failure
print("Fetch failed: \(error.localizedDescription)")
return nil
}
}
When I do:
if let topStoriesCacheData = DataCache.defaultCache.readDataForKey("TOPSTORIESCACHEDATA") {
self.updateTopStories(topStoriesCacheData)
}
crashes on the if statement, doesn't even go inside
@huynguyencong
Needs update to silence 4.1 warnings
valuePointer.deinitialize() // 'deinitialize()' is deprecated: the default argument to deinitialize(count:) has been removed, please specify the count explicitly
valuePointer.deallocate(capacity: 1) //'deallocate(capacity:)' is deprecated: Swift currently only supports freeing entire heap blocks, use deallocate() instead
not able to write custom object (subclass of nsobject) giving this compile time error
Cannot invoke 'write' with an argument list of type 'nsobject subclass'
@huynguyencong
Im using this library to cache stickers for iMessage Extension Sticker App
My images are png's with circle masks around them.
When i download and display them fresh from my database, the masks remain.
But when I load from cache, there is no longer a mask. Its a square image with a white background.
How can I fix this?
// HERE I CACHE IMAGE FROM THE URL
if let image: UIImage = imageFromURL(url: url!) {
DataCache.instance.write(image: image, forKey: sticker.downloadURL)
}
// HERE I RETRIEVE THE IMAGE FROM CACHE
if let cachedImage = DataCache.instance.readImageForKey(key: sticker.downloadURL) {
sticker.localURL = imageToURL(stickerName: sticker.name, image: cachedImage)
self.createSticker(sticker: sticker)
re
//HERE ONCE I GET IMAGE FROM URL, I STORE IT IN TEMP FOLDER
public func imageToURL(stickerName: String, image: UIImage) -> URL {
let url: URL = tempFilePath(stickerName: stickerName)
let imageData = UIImagePNGRepresentation(image)
do {
try imageData?.write(to: url)
} catch {
print(error)
}
return url
}
//HERE I TURN URL to UIIMAGE
public func imageFromURL(url: URL) -> UIImage {
var data: Data? = nil
do {
try data = Data(contentsOf: url)
} catch {
print(error)
}
return UIImage(data: data!)!
}
When I download and show on tableview most of time it crashes. I need to handle low memory device. I need help. Thank You..
@huynguyencong
I'm using this library in an iMessage Sticker app.
When submitting my build to iTunes for review, I got these errors.
Error 1: ITMS-90205 - Invalid Bundle
Invalid Bundle. The bundle at 'MyAppName.app/PlugIns/MessagesExtension.appex' contains disallowed nested bundles. Refer to https://developer.apple.com/go/?id=framework-imessage for a workaround.
Error 2: ITMS-90206 - Invalid Bundle
Invalid Bundle. The bundle at 'MyAppName.app/PlugIns/MessagesExtension.appex' contains disallowed file 'Frameworks'.
The solution I found from this stackoverflow thread was to run this script in the MessagesExtension
build phase.
cd "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/"
if [[ -d "Frameworks" ]]; then
rm -fr Frameworks
fi
But the problem is when I do this, xcode gives this error
dyld: Library not loaded: @rpath/DataCache.framework/DataCache
Referenced from: /private/var/containers/Bundle/Application/70472D74-21E6-4362-9481-8DC624D668DA/MyAppName.app/PlugIns/MessagesExtension.appex/MessagesExtension
Reason: image not found
Apple provides a work around here but it doesnt specifically address frameworks embedded with cocoapods so i dont know how to follow it.
My Pods
# Uncomment the next line to define a global platform for your project
platform :ios, '10.0'
target 'MyAppName' do
use_frameworks!
end
target 'MessagesExtension' do
pod 'Firebase'
pod 'DataCache'
pod 'BuddyBuildSDK'
pod 'Firebase/Storage'
pod 'FirebaseDatabase'
use_frameworks!
end
Hi team, is this framework is thread safe ?
I discovered your library via this post on stackoverflow. Could you provide an example of caching XML using your library?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.