Skip to content

WIP: GH-20: Create server cache - #131

Draft
etandon-coatue wants to merge 1 commit into
lsug:mainfrom
etandon:tmp/gh-20
Draft

WIP: GH-20: Create server cache#131
etandon-coatue wants to merge 1 commit into
lsug:mainfrom
etandon:tmp/gh-20

Conversation

@etandon-coatue

Copy link
Copy Markdown

No description provided.


object Meetup {

val eventMap: mutable.Map[String, (Int, LocalDateTime)] =

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! Thanks for opening this PR; Meetup has been down frequently so it would be nice to have some cache for it 😄.

There are a couple of points to consider:

  1. It would probably be best if we extracted the logic into a separate class and passed it into the apply method. This would mean that it's easier to test the cache behavior as an independent unit
  2. In general we avoid mutable state unless there's a good reason to have it (i.e. bottleneck for performance). We can use a Ref with an immutable map to get a primitive concurrent cache.
  3. In general, Map doesn't provide any guarantees about it's behaviour under concurrent conditions; looking at the implementation of Scala's Map, I think it would be fine, but it's not great to rely on implementation details.

I think sketching out how the solution might be used first before implementing it is a good idea. Here's a starting point.

trait Cache[F[_], K, V] {
  def fetch(key: K, retrieve: K => F[V]): F[V]
}

object Cache {
  def apply[F[_]: Sync, K, V](evictionTime: Duration): Cache[F, K, V] = { 
    ???
  }
}

Thanks for joining the gitter chat and let me know if you encounter any issues.

@etandon-coatue
etandon-coatue marked this pull request as draft May 17, 2021 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants