Priyansh-Kedia / OpenGraphParser

Open Graph Parser for Android
MIT License
85 stars 15 forks source link

Make the cache provider an injectable dependency #20

Closed Mek101 closed 1 year ago

Mek101 commented 1 year ago

This removes the hard-dependency on SharedPreference as a cache implementation and allows the user to supply their own

Priyansh-Kedia commented 1 year ago

Hello @Mek101 Thank you for your contribution

Can you please include the code where you use your injectable dependency of cache provider?

Thank you

Mek101 commented 1 year ago

You mean in the example application?

Priyansh-Kedia commented 1 year ago

Yes. I just tested out your code, and it works fine though.

Your solution works alright, but has one potential issue which I see. If the user wishes to implement caching, they need to create a class on their own and pass it as a parameter, but what if a user wishes to use the default shared preferences rather than creating one on their own. Also, this solution eliminates the ability for the user to choose if they wish to implement caching or not.

What are your thoughts?

Thanks

Mek101 commented 1 year ago

what if a user wishes to use the default shared preferences rather than creating one on their own.

They can simple create a SharedPrefsCacheProvider instance and pass it as an argument to the OpenGraphParser constructor.

this solution eliminates the ability for the user to choose if they wish to implement caching or not.

The cacheProvider parameter can be null, allowing the user to disable caching by providing no implementation.

I also added how to use the default provider with in the example application

Mek101 commented 1 year ago

I also made the member functions of CacheProvider suspendable so they can be used in coroutine-heavy contexts.

Priyansh-Kedia commented 1 year ago

@Mek101 This is great. I now understand how it would work. Thank you for your explanation.

I will test out your changes soon.

Thank you

Priyansh-Kedia commented 1 year ago

@Mek101 Thank you for your contribution.

Merging your changes