annotate MoinMoin/caching.py @ 931:141083b64fb1

whitespace and minor style changes only
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 08 Jul 2006 21:21:36 +0200
parents 6cc24670fd0f
children 6bc162aba29d
rev   line source
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
2 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
3 MoinMoin caching module
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
4
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
5 @copyright: 2001-2004 by Jürgen Hermann <jh@web.de>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
6 @license: GNU GPL, see COPYING for details.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
7 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
8
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
9 import os
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
10 from MoinMoin import config
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
11 from MoinMoin.util import filesys
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
12
402
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
13 locking = 1
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
14 if locking:
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
15 from MoinMoin.util import lock
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 902
diff changeset
16
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
17 class CacheEntry:
902
6cc24670fd0f Speeded up linkto: search by avoiding read locks on pagelinks retrieval.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 683
diff changeset
18 def __init__(self, request, arena, key, scope='page_or_wiki', do_locking=True):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
19 """ init a cache entry
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
20 @param request: the request object
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
21 @param arena: either a string or a page object, when we want to use
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
22 page local cache area
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
23 @param key: under which key we access the cache content
902
6cc24670fd0f Speeded up linkto: search by avoiding read locks on pagelinks retrieval.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 683
diff changeset
24 @param lock: if there should be a lock, normally True
681
2d5883e4b82c scope == {'item', 'wiki', 'farm'} for caching
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 680
diff changeset
25 @param scope: the scope where we are caching:
2d5883e4b82c scope == {'item', 'wiki', 'farm'} for caching
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 680
diff changeset
26 'item' - an item local cache
2d5883e4b82c scope == {'item', 'wiki', 'farm'} for caching
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 680
diff changeset
27 'wiki' - a wiki local cache
2d5883e4b82c scope == {'item', 'wiki', 'farm'} for caching
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 680
diff changeset
28 'farm' - a cache for the whole farm
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
29 """
412
481c432b3d11 fix some error handlers, logging for caching lock failures
Thomas Waldmann <tw@waldmann-edv.de>
parents: 402
diff changeset
30 self.request = request
683
a2beb43407ea deprecate usage of CacheEntry without explicit scope
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 681
diff changeset
31 if scope == 'page_or_wiki': # XXX DEPRECATED, remove later
680
d6556513c4d3 add scope param to CacheEntry, scope=='farm' uses farmwide caching, use it for i18n
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 463
diff changeset
32 if isinstance(arena, str):
d6556513c4d3 add scope param to CacheEntry, scope=='farm' uses farmwide caching, use it for i18n
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 463
diff changeset
33 self.arena_dir = os.path.join(request.cfg.cache_dir, request.cfg.siteid, arena)
d6556513c4d3 add scope param to CacheEntry, scope=='farm' uses farmwide caching, use it for i18n
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 463
diff changeset
34 filesys.makeDirs(self.arena_dir)
d6556513c4d3 add scope param to CacheEntry, scope=='farm' uses farmwide caching, use it for i18n
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 463
diff changeset
35 else: # arena is in fact a page object
d6556513c4d3 add scope param to CacheEntry, scope=='farm' uses farmwide caching, use it for i18n
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 463
diff changeset
36 self.arena_dir = arena.getPagePath('cache', check_create=1)
681
2d5883e4b82c scope == {'item', 'wiki', 'farm'} for caching
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 680
diff changeset
37 elif scope == 'item': # arena is a Page instance
2d5883e4b82c scope == {'item', 'wiki', 'farm'} for caching
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 680
diff changeset
38 # we could move cache out of the page directory and store it to cache_dir
2d5883e4b82c scope == {'item', 'wiki', 'farm'} for caching
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 680
diff changeset
39 self.arena_dir = arena.getPagePath('cache', check_create=1)
2d5883e4b82c scope == {'item', 'wiki', 'farm'} for caching
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 680
diff changeset
40 elif scope == 'wiki':
2d5883e4b82c scope == {'item', 'wiki', 'farm'} for caching
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 680
diff changeset
41 self.arena_dir = os.path.join(request.cfg.cache_dir, request.cfg.siteid, arena)
2d5883e4b82c scope == {'item', 'wiki', 'farm'} for caching
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 680
diff changeset
42 filesys.makeDirs(self.arena_dir)
680
d6556513c4d3 add scope param to CacheEntry, scope=='farm' uses farmwide caching, use it for i18n
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 463
diff changeset
43 elif scope == 'farm':
d6556513c4d3 add scope param to CacheEntry, scope=='farm' uses farmwide caching, use it for i18n
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 463
diff changeset
44 self.arena_dir = os.path.join(request.cfg.cache_dir, '__common__', arena)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
45 filesys.makeDirs(self.arena_dir)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
46 self.key = key
902
6cc24670fd0f Speeded up linkto: search by avoiding read locks on pagelinks retrieval.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 683
diff changeset
47 self.locking = do_locking and locking
6cc24670fd0f Speeded up linkto: search by avoiding read locks on pagelinks retrieval.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 683
diff changeset
48 if self.locking:
412
481c432b3d11 fix some error handlers, logging for caching lock failures
Thomas Waldmann <tw@waldmann-edv.de>
parents: 402
diff changeset
49 self.lock_dir = os.path.join(self.arena_dir, '__lock__')
481c432b3d11 fix some error handlers, logging for caching lock failures
Thomas Waldmann <tw@waldmann-edv.de>
parents: 402
diff changeset
50 self.rlock = lock.ReadLock(self.lock_dir, 60.0)
481c432b3d11 fix some error handlers, logging for caching lock failures
Thomas Waldmann <tw@waldmann-edv.de>
parents: 402
diff changeset
51 self.wlock = lock.WriteLock(self.lock_dir, 60.0)
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 902
diff changeset
52
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
53 def _filename(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
54 return os.path.join(self.arena_dir, self.key)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
55
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
56 def exists(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
57 return os.path.exists(self._filename())
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
58
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
59 def mtime(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
60 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
61 return os.path.getmtime(self._filename())
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
62 except (IOError, OSError):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
63 return 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
64
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
65 def needsUpdate(self, filename, attachdir=None):
412
481c432b3d11 fix some error handlers, logging for caching lock failures
Thomas Waldmann <tw@waldmann-edv.de>
parents: 402
diff changeset
66 if not self.exists():
481c432b3d11 fix some error handlers, logging for caching lock failures
Thomas Waldmann <tw@waldmann-edv.de>
parents: 402
diff changeset
67 return 1
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
68
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
69 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
70 ctime = os.path.getmtime(self._filename())
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
71 ftime = os.path.getmtime(filename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
72 except os.error:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
73 return 1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
74
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
75 needsupdate = ftime > ctime
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 902
diff changeset
76
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
77 # if a page depends on the attachment dir, we check this, too:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
78 if not needsupdate and attachdir:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
79 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
80 ftime2 = os.path.getmtime(attachdir)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
81 except os.error:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
82 ftime2 = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
83 needsupdate = ftime2 > ctime
931
141083b64fb1 whitespace and minor style changes only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 902
diff changeset
84
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
85 return needsupdate
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
86
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
87 def copyto(self, filename):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
88 import shutil
902
6cc24670fd0f Speeded up linkto: search by avoiding read locks on pagelinks retrieval.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 683
diff changeset
89 if not self.locking or self.locking and self.wlock.acquire(1.0):
402
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
90 try:
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
91 shutil.copyfile(filename, self._filename())
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
92 try:
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
93 os.chmod(self._filename(), 0666 & config.umask)
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
94 except OSError:
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
95 pass
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
96 finally:
902
6cc24670fd0f Speeded up linkto: search by avoiding read locks on pagelinks retrieval.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 683
diff changeset
97 if self.locking:
402
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
98 self.wlock.release()
412
481c432b3d11 fix some error handlers, logging for caching lock failures
Thomas Waldmann <tw@waldmann-edv.de>
parents: 402
diff changeset
99 else:
463
051f79718bdd fixing yet another bug in error logging calls
Thomas Waldmann <tw@waldmann-edv.de>
parents: 458
diff changeset
100 self.request.log("Can't acquire write lock in %s" % self.lock_dir)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
101
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
102 def update(self, content, encode=False):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
103 if encode:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
104 content = content.encode(config.charset)
902
6cc24670fd0f Speeded up linkto: search by avoiding read locks on pagelinks retrieval.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 683
diff changeset
105 if not self.locking or self.locking and self.wlock.acquire(1.0):
402
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
106 try:
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
107 f = open(self._filename(), 'wb')
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
108 f.write(content)
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
109 f.close()
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
110 try:
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
111 os.chmod(self._filename(), 0666 & config.umask)
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
112 except OSError:
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
113 pass
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
114 finally:
902
6cc24670fd0f Speeded up linkto: search by avoiding read locks on pagelinks retrieval.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 683
diff changeset
115 if self.locking:
402
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
116 self.wlock.release()
412
481c432b3d11 fix some error handlers, logging for caching lock failures
Thomas Waldmann <tw@waldmann-edv.de>
parents: 402
diff changeset
117 else:
463
051f79718bdd fixing yet another bug in error logging calls
Thomas Waldmann <tw@waldmann-edv.de>
parents: 458
diff changeset
118 self.request.log("Can't acquire write lock in %s" % self.lock_dir)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
119
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
120 def remove(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
121 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
122 os.remove(self._filename())
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
123 except OSError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
124 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
125
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
126 def content(self, decode=False):
902
6cc24670fd0f Speeded up linkto: search by avoiding read locks on pagelinks retrieval.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 683
diff changeset
127 if not self.locking or self.locking and self.rlock.acquire(1.0):
402
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
128 try:
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
129 f = open(self._filename(), 'rb')
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
130 data = f.read()
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
131 f.close()
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
132 finally:
902
6cc24670fd0f Speeded up linkto: search by avoiding read locks on pagelinks retrieval.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 683
diff changeset
133 if self.locking:
402
c04edbe29fac add locking to caching module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
134 self.rlock.release()
412
481c432b3d11 fix some error handlers, logging for caching lock failures
Thomas Waldmann <tw@waldmann-edv.de>
parents: 402
diff changeset
135 else:
463
051f79718bdd fixing yet another bug in error logging calls
Thomas Waldmann <tw@waldmann-edv.de>
parents: 458
diff changeset
136 self.request.log("Can't acquire read lock in %s" % self.lock_dir)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
137 if decode:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
138 data = data.decode(config.charset)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
139 return data
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
140