Skip to content

Adding Caching Adapter, allows caching of _Role, _User and _SCHMEA (fixes #168) #1664

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

Merged
merged 3 commits into from
May 18, 2016
Merged

Adding Caching Adapter, allows caching of _Role, _User and _SCHMEA (fixes #168) #1664

merged 3 commits into from
May 18, 2016

Conversation

blacha
Copy link
Contributor

@blacha blacha commented Apr 28, 2016

No description provided.

@ghost
Copy link

ghost commented Apr 28, 2016

@blacha updated the pull request.

1 similar comment
@facebook-github-bot
Copy link

@blacha updated the pull request.

@@ -0,0 +1,70 @@
const DEFAULT_CACHE_TTL = 60 * 1000;
Copy link

Choose a reason for hiding this comment

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

Anyway to override this value with an ENV variable ou CLI option or Config value ?

Copy link
Contributor Author

@blacha blacha Apr 28, 2016

Choose a reason for hiding this comment

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

You can create a InMemoryCacheAdapter with any TTL you want when you initialize the server.

new ParseServer({
    cacheAdapter: new InMemoryCacheAdapter({ttl: 24 * 60 * 60 * 1000}) 
})

or you can completely disable it by having a cacheAdapter that just Promise.resolve(null) for gets/sets/del/clear

The TTL is only for Sessions, Roles and SCHEMA queries

Also any time a user modifies a Role or a Session the cache for those get destroyed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd still provide an option/env in the CLI.

@codecov-io
Copy link

codecov-io commented Apr 28, 2016

Current coverage is 92.40%

Merging #1664 into master will increase coverage by +0.14%

  1. 3 files in src were modified. more
    • Misses +1
    • Hits -1
  2. 2 files (not in diff) in src/Routers were modified. more
    • Misses +11
    • Hits -17
  3. 2 files (not in diff) in ...apters/Storage/Mongo were modified. more
    • Misses -16
    • Hits -18
  4. 1 files (not in diff) in src were modified. more
    • Misses -3
    • Hits -6
@@             master      #1664   diff @@
==========================================
  Files            87         91     +4   
  Lines          6201       6240    +39   
  Methods        1070       1083    +13   
  Messages          0          0          
  Branches       1289       1269    -20   
==========================================
+ Hits           5721       5766    +45   
+ Misses          480        474     -6   
  Partials          0          0          

Powered by Codecov. Last updated by 19e7407...e2928a1

@Salakar
Copy link

Salakar commented May 3, 2016

@blacha not trying to be pedantic 🙈 but any reason you're calling the set cache method put?

Would it make more sense to call it set, to match Redis, Memcache, object getter/setter etc method names?

@gfosco
Copy link
Contributor

gfosco commented May 3, 2016

@flovilmart or @nlutsenko any thoughts here?

@blacha
Copy link
Contributor Author

blacha commented May 4, 2016

@Salakar I based the implementation off library that I've used in the past and that used put I think your right set would be a better name as Redis/Memcache is what I want this cache adapter to be backed by eventually.

Ill update this pull request when I get home from work.

@ghost
Copy link

ghost commented May 4, 2016

@blacha updated the pull request.

@drew-gross
Copy link
Contributor

A couple comments:

  1. This cache adapter seems to have a contract that the promise returned by get must never reject. Are you sure thats what we want? I could see arguments on both sides.

  2. I'd rather have no cache by default. I don't want people to get surprised by cache-related inconsistencies when they start running multiple parse servers.

  3. Needs a rebase.

@blacha
Copy link
Contributor Author

blacha commented May 12, 2016

@drew-gross

  1. I think rejecting should be left for serious errors in the adapter (Failed to connect to Redis/memcache/, Out of memory etc..), we could in theory capture the rejections in the controller then Log the error and resolve a null (not cached).
  2. No cache is also possible, The only reason I had it caching by default was that it is replacing something that was already caching (Sessions I think), so if we disable it here it will be a performance regression until people update their configs. Another option would be a lower TTL? 5 - 30 seconds?
    • The cache is also "cleared" if anyone updates the _Role collection. so unless someone is manually changing the database they shouldn't notice any stale cached _Roles.
  3. Will do, after we decide on default to: No Cache or Lower TTL.

@drew-gross
Copy link
Contributor

  1. Sure, the question is whether we want to fail the whole request when only the cache is down. Some applications will be able to handle the load with higher response times when the cache is down, some will fall over. I think failing the whole request is reasonable, but we should do something to at least help the user figure out whats wrong. Maybe later we can have the server let you choose whether to fail the whole request or load from the backing store.
  2. Fair enough. I think 5s is a reasonable default TTL. Long enough that things will usually remain in the cache for multiple requests that are triggered by a single user action, short enough that you can usually save, refresh once or twice, hit a different server, and see the new data.
  3. 👍

ttl = NaN;
}

var record = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we handle value == null as a delete?

@ghost
Copy link

ghost commented May 12, 2016

@blacha updated the pull request.

@blacha blacha closed this May 13, 2016
@blacha blacha reopened this May 13, 2016
@drew-gross drew-gross changed the title Adding Caching Adapter, allows caching of _Role, _User and _SCHMEA Adding Caching Adapter, allows caching of _Role, _User and _SCHMEA (fixes #168) May 13, 2016
@ghost
Copy link

ghost commented May 17, 2016

@blacha updated the pull request.

@blacha blacha merged commit 8c09c3d into parse-community:master May 18, 2016
@gnz00
Copy link

gnz00 commented May 18, 2016

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.

9 participants