Sajan:
I have only one controller and some actions in it to handle different functionalities related to IMAP. So my problem is I don't want to create a separate connection for every action. For example in an action I can do something like(it is not the actual code):
Related Articles
def index
@imap = Net::IMAP.new(server, 993, true)
@imap.login(user, password)
@imap.select("INBOX")
end
Again in another action inside the same controller, if I need to do something related to IMAP then I will have to create the @imap
variable again.
I am working with IMAP first time so as per my understanding new
method in each action will create another connection to the server and I have heard google has connection limit (15) for the number of IMAP connections.
I can not serialize this connection object or store it in any other service like Redis or Memcached or cache it, So how can I create this connection once and use it all other actions, at least actions inside the same controller if possible? If not possible then any other solutions to handle this problem?
And of course I can cache the data I need from the mailbox but that can't help much since there are some other actions which won't need the data, it will need to do so some operations in the mailbox like deleting mails, so that will need the connection instance.
Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE