Giter Site home page Giter Site logo

Comments (6)

jakecraige avatar jakecraige commented on July 28, 2024

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:

  1. View a TweetsViewController which has a CollectionDataProvider<Tweet> and implements the delegate.
  2. I click a tweet which shows the EditTweetViewController
  3. 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 the EditTweetViewController of the nav stack to go back.
  4. I expect to see the TweetsViewController and that the collectionDataProviderHasUpdatedData 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.

plivesey avatar plivesey commented on July 28, 2024

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.

plivesey avatar plivesey commented on July 28, 2024

Oh, one other thing to check. Are you setting the delegate of your data provider? Sometimes an easy thing to forget :)

from rocketdata.

jakecraige avatar jakecraige commented on July 28, 2024

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.

jakecraige avatar jakecraige commented on July 28, 2024

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.

plivesey avatar plivesey commented on July 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.