rtorrent-python icon indicating copy to clipboard operation
rtorrent-python copied to clipboard

Metadata objects

Open cjlucas opened this issue 11 years ago • 0 comments

NOTE: This is a proposed feature, feel free to add your thoughts or opinions

Background Info

Previously, when a method backed by a RPC call was executed, the result would be cached in an instance variable for that object. Therefore, the cache would be directly tied to the object. Also, this feature was essentially broken. For example, if Torrent.get_priority() set an instance variable priority whenever it was called. The problem is that it's "setter" counterpart Torrent.set_priority(priority) also stores it's result in the priority instance variable, even though it always returns 0.

Proposed Change

Instead of just avoid writing to the instance variable when a setter method is called, I feel it's best to do away with the idea entirely. As an alternative solution, I've come up with the idea of Metadata objects, where each RTorrent/Torrent/File/Tracker/Peer class would have a corresponding metadata class. These classes would be completed decoupled from their RPC-backed counterparts.

As they are intended hold cached data, these metadata objects would only contain getter methods, but the methods have the same signature their RPCObject counterparts. They are not intended to be created by the user, but by methods such as Torrent.get_metadata().

Example

# Assume we have a instance of Torrent, called t.

# Call the RPC backed is_accepting_seeders() method
t.is_accepting_seeders()
# True

metadata = t.get_metadata()
# metadata is an instance of TorrentMetadata

# Get the cached value of is_accepting_seeders()
metadata.is_accepting_seeders()
# True
# ... extract more data from the cache

cjlucas avatar Oct 25 '14 22:10 cjlucas