Patch Set 3:

Introducing a class hierarchy similar to AnyObjectId would be a very big change.
What about the following simple solution: add a member "readonly" to DirCache and DirCacheEntry. Write methods check the flag and throw IllegalStateExceptions.