Wednesday
21
Dec 2005

Eclipse comands respect

(4:34 pm) Tags: [Quotes]

Talking in IM with someone who is now hacking on and in Eclipse full time:

me: what’s happenin’?
him: I’m neck-deep in Eclipse guts. You?
me: How much do you love Eclipse now? ;)
him: I wouldn’t say love, but I definitely respect it. Kind of like a bear or lion. :)

Popularity: 23%

Comments: (0)

L1/L2 Cache object for django

(11:50 am) Tags: [Software, Projects]

I started hacking on an L1/L2 cache implementation for django, and since I won’t be able to finish it anytime soon, I am posting it here for someone else to pick up and use.

If you are using a backing cache such as _FileCache or _DBCache, it can be a might slow for frequently cached items. So sometimes a _LocMemCache is more your style. But you still want to share the cached data between multiple systems. Now you can have your cake and eat it too!

I tested with _LocMemCache as the L1, and both _MemCache and _FileCache as the backend. That way you could cache 500 items locally, and as many as you can handle remotely. I use it for frequently used configuration data right now, and it speeds up the logic quite well.

What is left to do? Well, if you wanted to use it in django, you would need to register it in the cache infrastructure, add a parser to create an L1 and L2 instance, etc. If anyone wants to put it into django, you are more than welcome.

class L1L2Cache:
    \"Thread-safe L1/L2 cache.\"
    def __init__(self, l1, l2):
        self._l1 = l1
        self._l2 = l2
        self._lock = RWLock()
	
    def get(self, key, default=None):
        #print \"get(%s)\" % key
        result = None
        self._lock.reader_enters()
        try:
            result = self._l1.get(key, default)
            if result == None:
                result = self._l2.get(key, default)
                if result:
                    self._l1.set(key, result, None)
                    return result
                else:
                    return default
            else:
                return result
        finally:
            self._lock.reader_leaves()
	
    def set(self, key, value, timeout=None):
        self._lock.writer_enters()
        try:
            self._l1.set(key, value, timeout)
            self._l2.set(key, value, timeout)
        finally:
            self._lock.writer_leaves()
	
    def delete(self, key):
        self._lock.writer_enters()
        try:
            self._l1.delete(key)
            self._l2.delete(key)
        finally:
            self._lock.writer_leaves()
	
    def get_many(self, keys):
        d = {}
        for k in keys:
            val = self.get(k)
            if val is not None:
                d[k] = val
        return d
	
    def has_key(self, key):
        return self.get(key) is not None

Update: You just have to love WordPress for esacping my quotes that don’t need it. Thanks WordPress!

Popularity: 29%

Comments: (0)