summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bangert <ben@groovie.org>2011-10-16 10:31:53 -0700
committerBen Bangert <ben@groovie.org>2011-10-16 10:31:53 -0700
commit3fb996e9ee529f7305569d423848c2c61ac3def7 (patch)
tree28b05f6a574cc075637f01aef911748ab4344c57
parent20cfad928c8dbae46e309f1e6150affd9d2b48c5 (diff)
parenta1cb7151a4c06a9bbabad19283a58b43be2a63f2 (diff)
downloadroutes-3fb996e9ee529f7305569d423848c2c61ac3def7.tar.gz
Merge
--HG-- branch : trunk
-rw-r--r--routes/lru.py70
-rw-r--r--routes/mapper.py11
-rw-r--r--setup.py3
3 files changed, 9 insertions, 75 deletions
diff --git a/routes/lru.py b/routes/lru.py
deleted file mode 100644
index 9fb2329..0000000
--- a/routes/lru.py
+++ /dev/null
@@ -1,70 +0,0 @@
-"""LRU caching class and decorator"""
-import threading
-
-_marker = object()
-
-class LRUCache(object):
- def __init__(self, size):
- """ Implements a psueudo-LRU algorithm (CLOCK) """
- if size < 1:
- raise ValueError('size must be >1')
- self.clock = []
- for i in xrange(0, size):
- self.clock.append({'key':_marker, 'ref':False})
- self.size = size
- self.maxpos = size - 1
- self.hand = 0
- self.data = {}
- self.lock = threading.Lock()
-
- def __contains__(self, key):
- return key in self.data
-
- def __getitem__(self, key, default=None):
- try:
- datum = self.data[key]
- except KeyError:
- return default
- pos, val = datum
- self.clock[pos]['ref'] = True
- hand = pos + 1
- if hand > self.maxpos:
- hand = 0
- self.hand = hand
- return val
-
- def __setitem__(self, key, val, _marker=_marker):
- hand = self.hand
- maxpos = self.maxpos
- clock = self.clock
- data = self.data
- lock = self.lock
-
- end = hand - 1
- if end < 0:
- end = maxpos
-
- while 1:
- current = clock[hand]
- ref = current['ref']
- if ref is True:
- current['ref'] = False
- hand = hand + 1
- if hand > maxpos:
- hand = 0
- elif ref is False or hand == end:
- lock.acquire()
- try:
- oldkey = current['key']
- if oldkey in data:
- del data[oldkey]
- current['key'] = key
- current['ref'] = True
- data[key] = (hand, val)
- hand += 1
- if hand > maxpos:
- hand = 0
- self.hand = hand
- finally:
- lock.release()
- break \ No newline at end of file
diff --git a/routes/mapper.py b/routes/mapper.py
index 18ade09..9befa7d 100644
--- a/routes/mapper.py
+++ b/routes/mapper.py
@@ -3,8 +3,10 @@ import re
import sys
import threading
+import pkg_resources
+from repoze.lru import LRUCache
+
from routes import request_config
-from routes.lru import LRUCache
from routes.util import controller_scan, MatchException, RoutesException
from routes.route import Route
@@ -736,8 +738,9 @@ class Mapper(SubMapperParent):
# Check the url cache to see if it exists, use it if it does
for key in [cache_key, cache_key_script_name]:
- if key in self.urlcache:
- return self.urlcache[key]
+ val = self.urlcache.get(key, self)
+ if val != self:
+ return val
actionlist = self._gendict.get(controller) or self._gendict.get('*', {})
if not actionlist and not args:
@@ -832,7 +835,7 @@ class Mapper(SubMapperParent):
else:
key = cache_key
if self.urlcache is not None:
- self.urlcache[key] = str(path)
+ self.urlcache.put(key, str(path))
return str(path)
else:
continue
diff --git a/setup.py b/setup.py
index a8698f6..1af1a27 100644
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ except ImportError:
use_setuptools()
from setuptools import setup, find_packages
-version = '1.12.3'
+version = '2.0'
setup(name="Routes",
version=version,
@@ -23,6 +23,7 @@ A Routing package for Python that matches URL's to dicts and vice versa
"Topic :: Software Development :: Libraries :: Python Modules",
],
author='Ben Bangert',
+ install_requires=['repoze.lru>=0.3'],
author_email='ben@groovie.org',
url='http://routes.groovie.org/',
zip_safe=False,