What is the difference between DistributedCache.getCacheFiles() and DistributedCache.getLocalCacheFiles()
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
In old Hadoop MapReduce APIs, DistributedCache.getCacheFiles() and DistributedCache.getLocalCacheFiles() sound similar but answer different questions. One tells you which cache files were configured for the job as distributed URIs, while the other tells you where those files were localized on the task node's local filesystem.
getCacheFiles() Returns the Declared Cache URIs
When a job adds files to the distributed cache, Hadoop stores their source locations as URIs.
The important point is that these are not the paths you normally open inside a mapper task. They are the original configured resource locations, often on HDFS or another supported filesystem.
Use this when you want to inspect job configuration or verify that the correct files were attached.
getLocalCacheFiles() Returns the Localized Paths
Before a task runs, Hadoop copies distributed-cache resources to the local node. getLocalCacheFiles() returns those local paths.
These paths are what task code typically opens when it needs to read reference data efficiently from local disk rather than from HDFS on every record.
Example mapper setup:
Think of the Difference as Remote Versus Local View
A practical mental model is:
- '
getCacheFiles()= what was declared for the job' - '
getLocalCacheFiles()= where it ended up on this node'
That distinction matters because a file can originate at hdfs:///... but be accessed locally as a task-specific cached copy under a different path.
If your mapper needs to open the actual file during execution, the local path is usually what you want.
Remember the API Age
One more wrinkle is that DistributedCache itself belongs to older Hadoop APIs and has been deprecated in favor of newer configuration patterns such as Job.addCacheFile(...). The conceptual distinction still matters, though, because localization behavior did not disappear.
Newer-style job setup:
The same underlying idea remains: configured cache resource versus localized on-node file.
When Each Method Is Useful
Use getCacheFiles() when:
- validating job setup
- logging configured resources
- comparing declared cache URIs
Use getLocalCacheFiles() when:
- opening the cached file in mapper or reducer code
- checking whether localization succeeded
- reading local task-node copies for speed
Keeping those roles separate makes the API much less confusing.
Common Pitfalls
- Trying to open a URI from
getCacheFiles()as if it were already a local file path. - Assuming both methods return the same information in a different type.
- Forgetting that distributed-cache resources are localized before task execution.
- Using old
DistributedCacheexamples without noticing API deprecation in newer Hadoop versions. - Debugging the wrong layer by checking local paths when the real problem is that the job never added the URI correctly.
Summary
- '
getCacheFiles()returns the original configured cache URIs.' - '
getLocalCacheFiles()returns the localized paths on the task node.' - Use the local form when task code needs to read the cached file.
- Use the URI form when inspecting job configuration.
- Even in newer Hadoop APIs, the remote-versus-local distinction still matters.
Related reading
- What is the differences between Apache Spark and Apache Apex?
- What is the optimal way to read from multiple Kafka topics and write to different sinks using Spark Structured Streaming?
- what is this topic __consumer_offsets in Kafka
- What is transformation_ctx used for in aws glue?
- What is the difference between ''E'', ''T'', and ''?'' for Java generics?
- What is the difference between Enum.name and Enum.toString?
- What ways can a Consumer consume message in Kafka?
- What's the most elegant/right way to stop a spark job running on a Kubernetes cluster?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.