Question about channel instances, lifetimes

Hi,
 
I am in the middle of my first Plex channel and I was thinking of ways to optimise the number of network requests, which raised some questions about the runtime behaviour of the Plex channel code.
 
Q1: How many instances of my channel are created at runtime? Is it just one globally or one per client, or one per request?
 
This is useful to know because for example I would like to fetch a list of content and cache it across my channel because for a specific user login the content won't change very often. At the moment I fetch it from the server each time I need it, but I would like to fetch it once after the user login and then keep it cached somewhere for use in future requests.
 
It is also useful to know because the service API I am using has a "device" parameter that is passed during login. Ideally I would like to detect what type of client is accessing the channel and then use the correct value for the "device" parameter. But this might be tricky if the channel is a single instance shared between multiple clients, they won't all be able to login with their own device-type at the same time.
 
 
Q2: How are the channel-specific preferences stored? Is it once per channel on the server, or once per client? Can different clients have their own set of preference values?
 
This is useful to know because I might want a different set of preference values depending on the type of client I am using to access the channel. I'm thinking of things like bitrates, formats, etc.
 
Thanks in advance,
 
Charlie
 
Hi,
 
I am in the middle of my first Plex channel and I was thinking of ways to optimise the number of network requests, which raised some questions about the runtime behaviour of the Plex channel code.
 
Q1: How many instances of my channel are created at runtime? Is it just one globally or one per client, or one per request?
 
This is useful to know because for example I would like to fetch a list of content and cache it across my channel because for a specific user login the content won't change very often. At the moment I fetch it from the server each time I need it, but I would like to fetch it once after the user login and then keep it cached somewhere for use in future requests.
 
It is also useful to know because the service API I am using has a "device" parameter that is passed during login. Ideally I would like to detect what type of client is accessing the channel and then use the correct value for the "device" parameter. But this might be tricky if the channel is a single instance shared between multiple clients, they won't all be able to login with their own device-type at the same time.
 
 
Q2: How are the channel-specific preferences stored? Is it once per channel on the server, or once per client? Can different clients have their own set of preference values?
 
This is useful to know because I might want a different set of preference values depending on the type of client I am using to access the channel. I'm thinking of things like bitrates, formats, etc.
 
Thanks in advance,
 
Charlie

Q1:  I don't know for sure, but I expect that it's one instance per client as they are run on demand (and not left running and accessed).  In terms of cacheing, if you're accessing the same URL PMS has cacheing built into it and handles it all quite transparently, so I wouldn't worry about it too much in those terms if it's a repeat URL and you're not limiting any cache specifically.

Q2:  I'm pretty sure it's by channel (not per user), the preferences are stored on the server so you only get one set of preferences per channel as far as I know.  Multi-user is only supported on a local network with PMS (and not by sharing via myplex), so depending on your setup this may or may not even come into play for you.

Thanks again Gerk, good to know.