I was wondering what is the scope of a cached RDD. For example:
// Cache an RDD.
rdd.cache
// Pass the RDD to a method of another class.
otherClass.calculate(rdd) // This method performs various actions.
// Pass the RDD to a method of the same class.
calculate(rdd) // This method also performs some actions.
// Perform an action in the same method where the RDD was cached.
rdd.count
In the example above, will the RDD be materialized once? (It won't have to be recreated?) What is the scope of caching?
And should I always unpersist the RDD after I used it, if I don't need it anymore?