jlhutch/pylru — Issue #2: clear cache for decorated method
Author: bielcardona
Created: 2011-12-23 10:43:30+00:00
State: open

Hi,

I am trying to use pylru to cache methods in a class. Say:

```python
class myclass(object):
def __init__(self,data):
self.data = data

@lrudecorator(100)
def longcomputation(self):
#do some "hard work" depending on self.data and store results in x
print "I am working hard"
x = self.data
return x

def update(self,newdata):
self.data = newdata
```

Now if I do:

```python
obj = myclass("mydata")
print obj.longcomputation()
obj.update("mychangeddata")
print obj.longcomputation()
```
I get

```python
I am working hard
mydata
mydata
```
printed on the console, as it should be.

The question I have is if there is some way to clear the cached method so that if I do:

```python
def update(self,newdata):
self.data = newdata
# "something to clear the cache for longcomputation"
```

I get

```python
I am working hard
mydata
I am working hard
mynewdata
```