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

Allow override of cache storage provider #74

Closed
muuvmuuv opened this issue Jun 17, 2022 · 4 comments · Fixed by #75
Closed

Allow override of cache storage provider #74

muuvmuuv opened this issue Jun 17, 2022 · 4 comments · Fixed by #75

Comments

@muuvmuuv
Copy link
Contributor

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

I am not able to change the storage provider from localStorage to something else

Expected behavior

A exposed HttpCacheStorage provider to modify it. We for example use CapacitorStorage.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


Angular version: 14


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: 17  
- Platform:  Mac 

Others:

@NetanelBasal
Copy link
Member

@muuvmuuv
Copy link
Contributor Author

Oh.. yes my bad. I was aware of that the time I installed cashew a while back and just forgot to look at it again. Sorry!

Unfortunately, I am stuck with overriding the http cache class provider. None of the internal classes are exported so my TypeScript compiler is reporting errors when importing them.

./src/app/core/http/http.module.ts:3:0-68 - Error: Module not found: Error: Package path ./lib/cache-storage is not exported from package @ngneat/cashew
@Injectable()
export class HttpCache /* implements HttpCacheLocalStorage */ {
  async has(key: string) {
    return !!(await Storage.get({ key: createKey(key) }))
  }

  async get(key: string) {
    return await Storage.get({ key: createKey(key) })
  }

  async set(key: string, response: HttpResponse<unknown>) {
    await Storage.set({
      key: createKey(key),
      value: JSON.stringify(response),
    })
  }

  async delete(key: string) {
    await Storage.remove({ key: createKey(key) })
  }

  clear() {
	// WIP
  }
}
import { HttpCacheStorage } from '@ngneat/cashew/lib/cache-storage'
// module provider...
    useHttpCacheLocalStorage,
    {
      provide: HttpCacheStorage,
      useClass: HttpCache,
    },

@NetanelBasal
Copy link
Member

Can you open a PR and export it, please?

@muuvmuuv
Copy link
Contributor Author

Working on it but don't have much free time ATM because I am still moving out. I am still testing the async stuff because my Provider is async.

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 a pull request may close this issue.

2 participants