Now this is the "how long is a piece of string question".....
So, myself, and this may be not the right thing, but will just say what I do....firstly is always use a quality cartridge ( branded Umarex or such like ) it is supposed - although I can neither prove or disprove, the better the cartridge the better the fit and allegedly the better cartridges are better for the seals - but again - cannot prove that sat here right now.
Lubes can be used for the seal / nipple - but I have never used one - some say it's a good thing - just don't know.
I would happily leave the CO2 attached in a pistol type canister setup for 4 - 5 days at room temperature - not in the garage or shed. I have no scientific reason for that, just my brain saying don't leave the CO2 in it too long.
In a rifle - well its a bit more sturdy, seals and retaining may be better, but again I would leave CO2 in mine for max 4-5 days - again no evidence its just what I do.
Thats it, probably pointless - but I offer what I do for what its worth.
Happily be proved totally wrong - I do normally shoot, finish the cartridge and then put away.