This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Credits to https://pdos.csail.mit.edu/6.824/notes/l-memcached.txt | |
k not in cache | |
C1 get(k), misses | |
C1 v1 = read k from DB | |
C2 writes k = v2 in DB | |
C2 delete(k) | |
C1 set(k, v1) | |
now mc has stale data, delete(k) has already happened | |
will stay stale indefinitely, until k is next written |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install libevent needed for memaslap | |
sudo apt-get install libevent-dev | |
cd libmemcached-1.0.18 | |
# Edit Makefile by adding LDFLAGS "-L/lib64 -lpthread" | |
# https://bugs.launchpad.net/libmemcached/+bug/1562677 | |
### diff of Makefile | |
# -LDFLAGS = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// condRelease releases this connection if the error pointed to by err | |
// is nil (not an error) or is predefined Reusable error | |
// The purpose is to not recycle TCP connections that are bad. | |
func (cn *conn) ConnRelease(err *error) { | |
if *err == nil || resumableError(*err) { | |
cn.release() | |
} else { | |
cn.nc.Close() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ConnectionOptions struct { | |
// The initial num of active connections when pool is initialised | |
// Pros: Warmup the connection pool with some connections on startup. | |
InitialActiveConnections int | |
// The maximum number of connections that can be active at any given | |
// time | |
MaxActiveConnections int | |
// The maximum number of idle connections per host that are kept alive by |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ConnectionPool interface { | |
// This gets an active connection from the connection pool if exists, | |
// else create a new connection. | |
Get() (net.Conn, error) | |
// This releases an active connection back to the connection pool. | |
Release(conn net.Conn) error | |
// This discards an active connection from the connection pool and | |
// closes the connection. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Adapted Example from: Protocol-oriented Programming in Swift - WWDC 2015 | |
* https://developer.apple.com/videos/play/wwdc2015/408/ | |
*/ | |
/** | |
* Without Self (protocol or class implementation) | |
* sortedKeys is a heterogeneous array of Ordered objects which could contain both Number and Label objects | |
* | |
* This implementation will raise an error if Self is being used: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Example from: Protocol-oriented Programming in Swift - WWDC 2015 | |
* https://developer.apple.com/videos/play/wwdc2015/408/ | |
*/ | |
protocol Ordered { | |
func precedes(other: Self) -> Bool | |
} | |
// value type struct | |
struct Number: Ordered { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Example from: Protocol-oriented Programming in Swift - WWDC 2015 | |
* https://developer.apple.com/videos/play/wwdc2015/408/ | |
*/ | |
class Ordered { | |
func precedes(other: Ordered) -> Bool { fatalError("implement me!") } | |
} | |
class Label : Ordered { var textL String = "" ... } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Example from Protocol Oriented Programming - Advanced Swift Programming - raywenderlich.com | |
* https://www.youtube.com/watch?v=ekYdBcl3dzs | |
*/ | |
protocol Geometry { | |
var size: CGSize { get } | |
func boundingBoxArea() -> CGFloat // area -> boundingBoxArea | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Adapted Example from Protocol Oriented Programming - Advanced Swift Programming - raywenderlich.com | |
* https://www.youtube.com/watch?v=ekYdBcl3dzs | |
*/ | |
// Base class for inheritance | |
class Shape { | |
var size: CGSize | |
func draw(on context: CGContext) { fatalError("override \(#function)") } | |
func area() -> CGFloat { return size.width * size.height } |
NewerOlder