{
    "content": [
        {
            "type": "text",
            "text": "# LWP::ConnCache (perldoc)\n\n## NAME\n\nLWP::ConnCache - Connection cache manager\n\n## SYNOPSIS\n\nuse LWP::ConnCache;\nmy $cache = LWP::ConnCache->new;\n$cache->deposit($type, $key, $sock);\n$sock = $cache->withdraw($type, $key);\n\n## DESCRIPTION\n\nThe \"LWP::ConnCache\" class is the standard connection cache manager for LWP::UserAgent.\n\n## Sections\n\n- **NAME**\n- **NOTE**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **METHODS**\n- **PROTOCOL METHODS**\n- **INTERNAL METHODS**\n- **SUBCLASSING**\n- **SEE ALSO**\n- **COPYRIGHT**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "LWP::ConnCache",
        "section": "",
        "mode": "perldoc",
        "summary": "LWP::ConnCache - Connection cache manager",
        "synopsis": "use LWP::ConnCache;\nmy $cache = LWP::ConnCache->new;\n$cache->deposit($type, $key, $sock);\n$sock = $cache->withdraw($type, $key);",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "NOTE",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 73,
                "subsections": []
            },
            {
                "name": "PROTOCOL METHODS",
                "lines": 17,
                "subsections": []
            },
            {
                "name": "INTERNAL METHODS",
                "lines": 17,
                "subsections": []
            },
            {
                "name": "SUBCLASSING",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "LWP::ConnCache - Connection cache manager\n",
                "subsections": []
            },
            "NOTE": {
                "content": "This module is experimental. Details of its interface is likely to change in the future.\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use LWP::ConnCache;\nmy $cache = LWP::ConnCache->new;\n$cache->deposit($type, $key, $sock);\n$sock = $cache->withdraw($type, $key);\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "The \"LWP::ConnCache\" class is the standard connection cache manager for LWP::UserAgent.\n",
                "subsections": []
            },
            "METHODS": {
                "content": "The following basic methods are provided:\n\nnew\nmy $cache = LWP::ConnCache->new( %options )\n\nThis method constructs a new LWP::ConnCache object. The only option currently accepted is\n\"totalcapacity\". If specified it initializes the \"totalcapacity\" in LWP::ConnCache option. It\ndefaults to 1.\n\ntotalcapacity\nmy $cap = $cache->totalcapacity;\n$cache->totalcapacity(0); # drop all immediately\n$cache->totalcapacity(undef); # no limit\n$cache->totalcapacity($number);\n\nGet/sets the number of connection that will be cached. Connections will start to be dropped when\nthis limit is reached. If set to 0, then all connections are immediately dropped. If set to\n\"undef\", then there is no limit.\n\ncapacity\nmy $httpcapacity = $cache->capacity('http');\n$cache->capacity('http', 2 );\n\nGet/set a limit for the number of connections of the specified type that can be cached. The\nfirst parameter is a short string like \"http\" or \"ftp\".\n\ndrop\n$cache->drop(); # Drop ALL connections\n# which is just a synonym for:\n$cache->drop(sub{1}); # Drop ALL connections\n# drop all connections older than 22 seconds and add a reason for it!\n$cache->drop(22, \"Older than 22 secs dropped\");\n# which is just a synonym for:\n$cache->drop(sub {\nmy ($conn, $type, $key, $deposittime) = @;\nif ($deposittime < 22) {\n# true values drop the connection\nreturn 1;\n}\n# false values don't drop the connection\nreturn 0;\n}, \"Older than 22 secs dropped\" );\n\nDrop connections by some criteria. The $checker argument is a subroutine that is called for each\nconnection. If the routine returns a TRUE value then the connection is dropped. The routine is\ncalled with \"($conn, $type, $key, $deposittime)\" as arguments.\n\nShortcuts: If the $checker argument is absent (or \"undef\") all cached connections are dropped.\nIf the $checker is a number then all connections untouched that the given number of seconds or\nmore are dropped. If $checker is a string then all connections of the given type are dropped.\n\nThe \"reason\" is passed on to the \"dropped\" in LWP::ConnCache method.\n\nprune\n$cache->prune();\n\nCalling this method will drop all connections that are dead. This is tested by calling the\n\"ping\" in LWP::ConnCache method on the connections. If the \"ping\" in LWP::ConnCache method\nexists and returns a false value, then the connection is dropped.\n\ngettypes\nmy @types = $cache->gettypes();\n\nThis returns all the \"type\" fields used for the currently cached connections.\n\ngetconnections\nmy @conns = $cache->getconnections(); # all connections\nmy @conns = $cache->getconnections('http'); # connections for http\n\nThis returns all connection objects of the specified type. If no type is specified then all\nconnections are returned. In scalar context the number of cached connections of the specified\ntype is returned.\n",
                "subsections": []
            },
            "PROTOCOL METHODS": {
                "content": "The following methods are called by low-level protocol modules to try to save away connections\nand to get them back.\n\ndeposit\n$cache->deposit($type, $key, $conn);\n\nThis method adds a new connection to the cache. As a result, other already cached connections\nmight be dropped. Multiple connections with the same type/key might be added.\n\nwithdraw\nmy $conn = $cache->withdraw($type, $key);\n\nThis method tries to fetch back a connection that was previously deposited. If no cached\nconnection with the specified $type/$key is found, then \"undef\" is returned. There is not\nguarantee that a deposited connection can be withdrawn, as the cache manger is free to drop\nconnections at any time.\n",
                "subsections": []
            },
            "INTERNAL METHODS": {
                "content": "The following methods are called internally. Subclasses might want to override them.\n\nenforcelimits\n$conn->enforcelimits([$type])\n\nThis method is called with after a new connection is added (deposited) in the cache or capacity\nlimits are adjusted. The default implementation drops connections until the specified capacity\nlimits are not exceeded.\n\ndropping\n$conn->dropping($connrecord, $reason)\n\nThis method is called when a connection is dropped. The record belonging to the dropped\nconnection is passed as the first argument and a string describing the reason for the drop is\npassed as the second argument. The default implementation makes some noise if the\n$LWP::ConnCache::DEBUG variable is set and nothing more.\n",
                "subsections": []
            },
            "SUBCLASSING": {
                "content": "For specialized cache policy it makes sense to subclass \"LWP::ConnCache\" and perhaps override\nthe \"deposit\" in LWP::ConnCache, \"enforcelimits\" in LWP::ConnCache, and \"dropping\" in\nLWP::ConnCache methods.\n\nThe object itself is a hash. Keys prefixed with \"cc\" are reserved for the base class.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "LWP::UserAgent\n",
                "subsections": []
            },
            "COPYRIGHT": {
                "content": "Copyright 2001 Gisle Aas.\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
                "subsections": []
            }
        }
    }
}