CacheBox: Enterprise Caching
2.x
2.x
  • Introduction
  • What's New With 2.1.0
  • What's New With 2.0.0
  • About This Book
  • Author
  • Overview
    • CacheBox RefCard
    • Useful Resources
    • Features at a Glance
    • System Requirements
  • Installing CacheBox
    • Installation
  • Caching Concepts
    • Caching Considerations
    • Cache Loading
    • Definitions
    • Java Soft References
  • Cache Topologies
    • Single Instance/In-Process
    • Single Instance/Out-Process
    • Replicated
    • Distributed
  • CacheBox Architecture
    • CacheFactory
    • CacheBoxConfig
    • EventManager
    • ColdBox
    • LogBox
    • ICacheProvider
    • ICacheStats
    • IObjectStore
    • IEvictionPolicy
    • AbstractEvictionPolicy
    • IColdboxApplicationCache
  • Creating CacheBox
    • Common CacheFactory Methods
    • Cache Cleanup/Reaping
  • CacheBox Configuration
    • CacheBox DSL
      • LogBoxConfig
      • Scope Registration
      • Default Cache
      • Caches
      • Listeners
    • CacheBox Config Object
    • ColdBox Configuration
  • Cache Providers
    • Couchbase Providers
    • CF Providers
    • Railo Providers
    • Mock Provider
    • CacheBox Provider
  • CacheBox Object Stores
    • ConcurrentStore
    • ConcurrentSoftReferenceStore
    • DiskStore
    • JDBCStore
    • BlackholeStore
  • CacheBox Eviction Policies
    • Using Your Own Policy
  • CacheBox Event Model
    • CacheBox Events
    • Provider Events
    • Cache Listeners
  • Cache Reporting
    • Creating Your Own Skins
      • Skin Templates
      • ReportHandler
        • Action Commands
Powered by GitBook
On this page

Was this helpful?

Edit on Git
Export as PDF
  1. Caching Concepts

Java Soft References

PreviousDefinitionsNextCache Topologies

Last updated 7 years ago

Was this helpful?

"In the past, developers didn't have much control over garbage collection or memory management. Java2 has changed that by introducing the java.lang.ref package. The abstract base class Reference is inherited by classes SoftReference, WeakReference and PhantomReference. SoftReferences are well suited for use in applications needing to perform caching."

Why is this? Well, a soft reference is nothing but a wrapper class that wraps an object in memory. Whenever the JVM requires memory and runs its reference rules, it can detect these soft references and decide to purge them if it meets the garbage collector rules. If it purges them, the wrapped object inside of the soft reference is marked for collection, but the java soft reference itself still exists. Therefore, the programmer can determine if the object inside the reference exists or not. If it does not exist, it means the object was garbage collected and I have no more object. I won't go into the implementation semantics of the cache, just theory. Please visit the references to understand more of how the ColdBox cache was built.

In summary, soft references are what determine if an object is still available or not. CacheBox cache can then run maintenance on itself and clean out all of its references for you if you are using the ConcurrentSoftReferenceStore object store.

Useful Resources

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ref/SoftReference.html
https://www.rallydev.com/community/engineering/java-references-strong-soft-weak-phantom