Comments (6)
I think part of my confusion around implementation is not understanding the difference between the model and collection cache. AFAICT they're separate things as far as RocketData is concerned, but I'm not sure if behind the scenes they should be backed by the same cache or not, or if I'm just misunderstanding.
Here's an example of a setup and what I'd expect to happen:
- View a
TweetsViewController
which has aCollectionDataProvider<Tweet>
and implements the delegate. - I click a tweet which shows the
EditTweetViewController
- I change the content and tap save. This creates a new version of the tweet with the updated content, and calls
DataModelManager.sharedInstance.update(updatedTweet)
. It then pops theEditTweetViewController
of the nav stack to go back. - I expect to see the
TweetsViewController
and that thecollectionDataProviderHasUpdatedData
is called with a change of the update of that tweet.
Here's my first attempt at a very simple in-memory cache: https://gist.github.com/jakecraige/1bbc28b8a69a12138e2006e6f7d61986
My assumption is that this will not work with that store, and I'd have to get a lot more creative with the caching to make it so.
Is that a correct? Am thinking about this the right way?
from rocketdata.
Hmmmm...so, this setup should definitely work. Some things to double check:
- Does your Tweet model have an id? Is the id of the editing tweet model the same as the one in your TweetsViewController?
- Are you using the same DataModelManager (since you have a sharedInstance, this seems likely)
For the difference between the collection and model cache, it's up to you. There doesn't need to be a different (for instance you could use [String: Any]
as a cache and optionally cast it as things come out). It's really up to you.
Looks like we also need a sample app for this library to show a simple setup.
from rocketdata.
Oh, one other thing to check. Are you setting the delegate of your data provider? Sometimes an easy thing to forget :)
from rocketdata.
Thanks! After our talk last night I think I know enough to keep experimenting. I'm going to close this since #3 will likely cover it.
from rocketdata.
Just wanted to leave a note about something I did today that Ben-G recommended. Since in my case, I don't actually care about anything being cached right now and mostly want to play with the consistency, I can implement a noop cache delegate and use it like that. Something like so:
class MyCacheDelegate: CacheDelegate {
let noCacheError = NSError(
domain: "",
code: 0,
userInfo: [NSLocalizedDescriptionKey: "No caching implemented"]
)
func modelForKey<T : SimpleModel>(cacheKey: String?, context: Any?, completion: (T?, NSError?) -> ()) {
completion(.None, noCacheError)
}
func collectionForKey<T: SimpleModel>(cacheKey: String?, context: Any?, completion: ([T]?, NSError?) -> ()) {
completion(.None, noCacheError)
}
func setModel<T: SimpleModel>(model: T, forKey cacheKey: String, context: Any?) { /* noop */ }
func setCollection<T: SimpleModel>(collection: [T], forKey cacheKey: String, context: Any?) { /* noop */ }
func deleteModel(model: SimpleModel, forKey cacheKey: String?, context: Any?) { /* noop */ }
}
from rocketdata.
Yeah, this definitely works. Perhaps because of this, it might be
interesting to make the CacheDelegate optional? Because some people may not
want any persistence.
On Fri, Jul 22, 2016 at 10:42 AM Jake Craige [email protected]
wrote:
Just wanted to leave a note about something I did today that Ben-G
recommended. Since in my case, I don't actually care about anything being
cached right now and mostly want to play with the consistency, I can
implement a noop cache delegate and use it like that. Something like so:class MyCacheDelegate: CacheDelegate {
let noCacheError = NSError(
domain: "",
code: 0,
userInfo: [NSLocalizedDescriptionKey: "No caching implemented"]
)func modelForKey(cacheKey: String?, context: Any?, completion: (T?, NSError?) -> ()) {
completion(.None, noCacheError)
}func collectionForKey<T: SimpleModel>(cacheKey: String?, context: Any?, completion: ([T]?, NSError?) -> ()) {
completion(.None, noCacheError)
}func setModel<T: SimpleModel>(model: T, forKey cacheKey: String, context: Any?) { /* noop / }
func setCollection<T: SimpleModel>(collection: [T], forKey cacheKey: String, context: Any?) { / noop / }
func deleteModel(model: SimpleModel, forKey cacheKey: String?, context: Any?) { / noop */ }
}—
You are receiving this because you commented.Reply to this email directly, view it on GitHub
#2 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABMNTRdBmSO1P7czt7jlGuEPpK-G3Josks5qYQERgaJpZM4JRbeM
.
from rocketdata.
Related Issues (20)
- Wrong version of ConsistencyManager installed when installing via cocoapods HOT 2
- Can u maintain an objective-c version? HOT 3
- How to purge all items in the DataProvide and empty the cache in one shot? HOT 1
- Using model objects in Objective-C HOT 3
- Can this lib be used in conjunction with Realm? HOT 2
- Can you provide a way to completely clean data HOT 3
- One-to-many relationship: retrieve child object from cache HOT 3
- Example App with complex models HOT 1
- Why does siblingProvidersForProvider not return current provider? HOT 1
- Handling cutdown API objects HOT 2
- Setting CollectionDataProvider cacheKey without setting data
- ConsistencyManager 5.1 and Cocoapods HOT 6
- Crash: DataProvider.swift line 92 DataProvider.init(dataModelManager : DataModelManager) -> DataProvider<A> HOT 10
- dataProviderHasUpdatedData is not called when passing a new different model to the DataProvider HOT 2
- fetchDataFromCache(withCacheKey:listenToModelIdentifier... methods unavailable HOT 8
- Notifying CollectionDataProvider of updates in a child model HOT 9
- 'dataProviderHasUpdatedData' delegate method is not called after updating to version 6.0.0/7.0.0 HOT 5
- Add SwiftUI support
- Catalyst compatibility HOT 1
- Request to updated SDK with the Privacy Manifest
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rocketdata.