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

DataSourceCache parameterised to F[_] #160

Merged
merged 11 commits into from
Sep 25, 2018
Merged

Conversation

purrgrammer
Copy link
Contributor

@purrgrammer purrgrammer commented Sep 20, 2018

I changed DataSourceCache so we can parameterise it to F[_] : Monad. It also helps for implementing custom caches that make use of io for serialization/deserialization.

@codecov
Copy link

codecov bot commented Sep 20, 2018

Codecov Report

Merging #160 into master will increase coverage by 4.08%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #160      +/-   ##
=========================================
+ Coverage   91.12%   95.2%   +4.08%     
=========================================
  Files           5       5              
  Lines         169     167       -2     
  Branches        5       4       -1     
=========================================
+ Hits          154     159       +5     
+ Misses         15       8       -7
Impacted Files Coverage Δ
shared/src/main/scala/fetch.scala 95.42% <100%> (+3.42%) ⬆️
shared/src/main/scala/cache.scala 100% <100%> (+20%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 27ea529...3c19563. Read the comment docs.

@purrgrammer purrgrammer changed the title DataSourceCache as abstract class instead of trait DataSourceCache parameterised to F[_] Sep 20, 2018
})
trait DataSourceCache[F[_]] {
def lookup[I, A](i: I, ds: DataSource[I, A])(
implicit C: ConcurrentEffect[F], P: Par[F]
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice if we didn't put these constraints on the methods anymore.

Now that we have parametrized DataSourceCache on F, the implementation could specify the constraints.
For example for InMemoryCache we would only need Applicative (Monad for foldLeftM).

Copy link
Contributor Author

@purrgrammer purrgrammer Sep 25, 2018

Choose a reason for hiding this comment

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

Good point, I'm going to try to remove these constraints from the trait.

@purrgrammer
Copy link
Contributor Author

@juanpedromoreno @peterneyens Updated with Peter's feedback, let me know if I can go ahead and merge this.

)(
implicit
P: Par[F],
C: ConcurrentEffect[F],
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be this replaced by Monad?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm afraid is not. The effect type F[_] of the DataSource instances requires a ConcurrentEffect[F] and Par[F]. For running F we need ContextShift[F] and Timer[F]so these are the less restrictive implicits.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need Sync for Ref.of and the DataSource methods still require ConcurrentEffect at the moment.
So performRun and co need ConcurrentEffect as well.

@@ -526,7 +526,7 @@ The default cache is implemented as an immutable in-memory map, but users are fr
There is no need for the cache to be mutable since fetch executions run in an interpreter that uses the state monad. Note that the `update` method in the `DataSourceCache` trait yields a new, updated cache.

```scala
trait DataSourceCache {
trait DataSourceCache[F[_]] {
def insert[F[_] : ConcurrentEffect, I, A](i: I, ds: DataSource[I, A], v: A): DataSourceIdentity, v: A): F[DataSourceCache]
def lookup[F[_] : ConcurrentEffect, I, A](i: I, ds: DataSource[I, A]): F[Option[A]]
Copy link
Contributor

Choose a reason for hiding this comment

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

These are no longer correct, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right!

)(
implicit
P: Par[F],
C: ConcurrentEffect[F],
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need Sync for Ref.of and the DataSource methods still require ConcurrentEffect at the moment.
So performRun and co need ConcurrentEffect as well.

@purrgrammer
Copy link
Contributor Author

@peterneyens @juanpedromoreno i opened #163 to discuss about the implicits required when implementing data sources, let me know your thoughts in there.

Can I merge this :shipit: ?

Copy link
Contributor

@peterneyens peterneyens left a comment

Choose a reason for hiding this comment

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

Nice improvement of DataSourceCache

Copy link
Contributor

@juanpedromoreno juanpedromoreno left a comment

Choose a reason for hiding this comment

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

Nice work 👌

@purrgrammer purrgrammer merged commit e7c7e1c into master Sep 25, 2018
bijancn pushed a commit to bijancn/fetch that referenced this pull request Sep 19, 2019
@fedefernandez fedefernandez deleted the parameterised-cache branch October 16, 2023 07:39
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.

3 participants