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

Add Account cache #1519

Merged
merged 4 commits into from
Oct 14, 2020
Merged

Add Account cache #1519

merged 4 commits into from
Oct 14, 2020

Conversation

laurb9
Copy link
Contributor

@laurb9 laurb9 commented Oct 1, 2020

Summary

Optional cache for Accounts (issue #1395, follow-up from #1426). This cache is not necessary for the current static file fetcher, it is intended to support upcoming http API and db fetchers.

Implementation

Added cache support for account fetcher.
Add new size_bytes parameter for in_memory_cache to control single cache.
Add necessary config validation so accounts uses size_bytes while the rest have request_cache_size_bytes
and imp_cache_size_bytes.
Removed some redundant tests and refactored others a little.

Example config:

accounts:
  in_memory_cache:
    type: lru
    ttl_seconds: 10
    size_bytes: 500000

Once the amp config split was moved to main config package,
these tests are checking the same thing twice
(that a fetcher can be created from a fetcher config).
Adds a new `size_bytes` parameter for in_memory_cache to control single caches such as Account, and corresponding validation.
```
accounts:
  in_memory_cache:
    type: lru
    ttl_seconds: 10
    size_bytes: 100000
```
Copy link
Collaborator

@bsardo bsardo left a comment

Choose a reason for hiding this comment

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

This is looking good.

config/stored_requests.go Outdated Show resolved Hide resolved
config/stored_requests_test.go Outdated Show resolved Hide resolved
config/stored_requests_test.go Show resolved Hide resolved
return f.fetcher.FetchAccount(ctx, accountID)
func (f *fetcherWithCache) FetchAccount(ctx context.Context, accountID string) (account json.RawMessage, errs []error) {
accountData := f.cache.Accounts.Get(ctx, []string{accountID})
// TODO: add metrics
Copy link
Collaborator

Choose a reason for hiding this comment

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

You mentioned the metrics will be a separate PR right? And you're also planning to add account HTTP and DB fetchers in their own PRs too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The metrics commit is ready, I can make a PR right after this, or add another commit here.
Account http is almost ready, will make a PR separately.
I will not have time this round for the Db fetcher, but I'll try to take a stab at it.

bsardo
bsardo previously approved these changes Oct 8, 2020
Copy link
Contributor

@mansinahar mansinahar left a comment

Choose a reason for hiding this comment

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

LGTM other than the minor comment above

if cfg.Size <= 0 {
errs = append(errs, fmt.Errorf("%s: in_memory_cache.size_bytes must be >= 0 when in_memory_cache.type=lru. Got %d", section, cfg.Size))
}
if cfg.RequestCacheSize > 0 || cfg.ImpCacheSize > 0 { // should this be a warning instead ? "field is ignored"
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think this should be fine with being a warning but either way, we should keep this consistent with what we do when size is specified in case of stored request/imp cache which right now is a warning

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 should have changed both at the same time, sorry.

Copy link
Contributor

Choose a reason for hiding this comment

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

No worries! Happens to all of us. Thank you for the PR :)

@SyntaxNode SyntaxNode merged commit c7ddfa6 into prebid:master Oct 14, 2020
@laurb9 laurb9 deleted the account-cache branch October 14, 2020 20:40
katsuo5 pushed a commit to flux-dev-team/prebid-server-1 that referenced this pull request Dec 1, 2020
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.

4 participants