Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of ClassKey #622

Merged
merged 8 commits into from Feb 17, 2023
Merged

Remove use of ClassKey #622

merged 8 commits into from Feb 17, 2023

Conversation

pjfanning
Copy link
Member

@pjfanning pjfanning commented Feb 17, 2023

In v2.14.3, these little used APIs (recently added and still changing):

  • ScalaAnnotationIntrospectorModule.setDescriptorCache
  • ScalaAnnotationIntrospectorModule.setScalaTypeCache

In v2.15.0, these APIs will remain deprecated but the input types will change:

  • ScalaAnnotationIntrospectorModule.setDescriptorCache - input and return type changes to LookupCache[String, BeanDescriptor]) - was LookupCache[ClassKey, BeanDescriptor])
  • ScalaAnnotationIntrospectorModule.setScalaTypeCache - input and return type changes to LookupCache[String, Boolean]) - was LookupCache[ClassKey, Boolean])

New functions added in v2.14.3 to replace these APIs:

  • ScalaAnnotationIntrospectorModule.setDescriptorCacheSize(size: Int) - beware that this clears existing entries in the descriptor cache
  • ScalaAnnotationIntrospectorModule.setScalaTypeCacheSize(size: Int) - beware that this clears existing entries in the scala type cache
  • setLookupCacheFactory(lookupCacheFactory: LookupCacheFactory) - beware that this clears existing entries in both caches

LookupCacheFactory is a new trait:

trait LookupCacheFactory {
  def createLookupCache[K, V](initialEntries: Int, maxEntries: Int): LookupCache[K, V]
}

Example implementation:

  class ConcurrentLookupCache[K, V]() extends LookupCache[K, V] {
    final private val cache = TrieMap.empty[K, V]

    override def put(key: K, value: V): V =
      cache.put(key, value).getOrElse(None.orNull).asInstanceOf[V]

    override def putIfAbsent(key: K, value: V): V =
      cache.putIfAbsent(key, value).getOrElse(None.orNull).asInstanceOf[V]

    override def get(key: Any): V = {
      cache.get(key.asInstanceOf[K]).getOrElse(None.orNull).asInstanceOf[V]
    }

    override def clear(): Unit = {
      cache.clear()
    }

    override def size: Int = cache.size
  }

  object ConcurrentLookupCacheFactory extends LookupCacheFactory {
    override def createLookupCache[K, V](initialEntries: Int, maxEntries: Int): LookupCache[K, V] =
      new ConcurrentLookupCache[K, V]
  }

@pjfanning pjfanning merged commit 4323e69 into 2.15 Feb 17, 2023
@pjfanning pjfanning deleted the remove-class-key branch February 17, 2023 22:24
pjfanning added a commit that referenced this pull request Feb 17, 2023
@pjfanning pjfanning added the 2.15 label Apr 4, 2023
@cowtowncoder cowtowncoder changed the title remove use of ClassKey Remove use of ClassKey Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant