Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zahra Rajabi
tweepy
Commits
f23acfdb
Commit
f23acfdb
authored
Aug 11, 2009
by
Josh Roesslein
Browse files
Added memcache client cache implementation.
parent
e60f5a8d
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
tweepy/cache.py
View file @
f23acfdb
...
...
@@ -11,6 +11,7 @@ import hashlib
import
fcntl
import
cPickle
as
pickle
from
.
import
memcache
from
.
error
import
TweepError
"""Cache interface"""
...
...
@@ -27,22 +28,22 @@ class Cache(object):
key: entry key
value: data of entry
"""
raise
NotImplemented
raise
NotImplemented
Error
def
get
(
self
,
key
,
timeout
=
None
):
"""Get cached entry if exists and not expired
key: which entry to get
timeout: override timeout with this value [optional]
"""
raise
NotImplemented
raise
NotImplemented
Error
def
cleanup
(
self
):
"""Delete any expired entries in cache."""
raise
NotImplemented
raise
NotImplemented
Error
def
flush
(
self
):
"""Delete all cached entries"""
raise
NotImplemented
raise
NotImplemented
Error
"""In-memory cache"""
class
MemoryCache
(
Cache
):
...
...
@@ -193,3 +194,35 @@ class FileCache(Cache):
if
entry
.
endswith
(
'.lock'
):
continue
self
.
_delete_file
(
os
.
path
.
join
(
self
.
cache_dir
,
entry
))
"""Memcache client"""
class
MemCache
(
Cache
):
def
__init__
(
self
,
servers
,
timeout
=
60
):
Cache
.
__init__
(
self
,
timeout
)
self
.
client
=
memcache
.
Client
(
servers
)
def
store
(
self
,
key
,
value
):
self
.
client
.
set
(
key
,
(
time
.
time
(),
value
),
time
=
self
.
timeout
)
def
get
(
self
,
key
,
timeout
=
None
):
obj
=
self
.
client
.
get
(
key
)
if
obj
is
None
:
return
None
created_time
,
value
=
obj
# check if value is expired
_timeout
=
self
.
timeout
if
timeout
is
None
else
timeout
if
_timeout
>
0
and
(
time
.
time
()
-
created_time
)
>=
_timeout
:
# expired! delete from cache
self
.
client
.
delete
(
key
)
return
None
return
value
def
cleanup
(
self
):
# not implemented for this cache
return
def
flush
(
self
):
self
.
client
.
flush_all
()
tweepy/memcache.py
0 → 100644
View file @
f23acfdb
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment