comparison src/core/xmpp.py @ 2109:85f3e12e984d

core (memory/cache): file caching handling, first draft: instead of having file caching handled individually by plugins, a generic module has been added in memory. - Cache can be global or associated to a profile. In the later case, client.cache can be used. - Cache are managed with unique ids (which can be any unique unicode, hash uuid, or something else). - To know if a file is in cache, getFilePath is used: if the file is in cache, its absolute path is returned, else None is returned. - To cache a file, cacheData is used with at list the source of cache (most of time plugin import name), and unique id. The method return file opened in binary writing mode (so cacheData can - and should - be used with "with" statement). - 2 files will be created: a metadata file (named after the unique id), and the actual file. - each file has a end of life time, after it, the cache is invalidated and the file must be requested again.
author Goffi <goffi@goffi.org>
date Thu, 05 Jan 2017 20:23:38 +0100
parents ad88808591ef
children 2d633b3c923d
comparison
equal deleted inserted replaced
2108:70f23bc7859b 2109:85f3e12e984d
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from sat.core.constants import Const as C 21 from sat.core.constants import Const as C
22 from sat.memory import cache
22 from twisted.internet import task, defer 23 from twisted.internet import task, defer
23 from twisted.words.protocols.jabber.xmlstream import XMPPHandler 24 from twisted.words.protocols.jabber.xmlstream import XMPPHandler
24 from twisted.words.protocols.jabber import xmlstream 25 from twisted.words.protocols.jabber import xmlstream
25 from twisted.words.protocols.jabber import error 26 from twisted.words.protocols.jabber import error
26 from twisted.words.protocols.jabber import jid 27 from twisted.words.protocols.jabber import jid
58 self.factory.clientConnectionLost = self.connectionLost 59 self.factory.clientConnectionLost = self.connectionLost
59 self.factory.maxRetries = max_retries 60 self.factory.maxRetries = max_retries
60 self.__connected = False 61 self.__connected = False
61 self.profile = profile 62 self.profile = profile
62 self.host_app = host_app 63 self.host_app = host_app
64 self.cache = cache.Cache(host_app, profile)
63 self._mess_id_uid = {} # map from message id to uid use in history. Key: (full_jid,message_id) Value: uid 65 self._mess_id_uid = {} # map from message id to uid use in history. Key: (full_jid,message_id) Value: uid
64 self.conn_deferred = defer.Deferred() 66 self.conn_deferred = defer.Deferred()
65 self._progress_cb = {} # callback called when a progress is requested (key = progress id) 67 self._progress_cb = {} # callback called when a progress is requested (key = progress id)
66 self.actions = {} # used to keep track of actions for retrieval (key = action_id) 68 self.actions = {} # used to keep track of actions for retrieval (key = action_id)
67 69