{"id":21865431,"url":"https://github.com/wa-lead/cacheking","last_synced_at":"2025-10-19T07:44:20.269Z","repository":{"id":225731053,"uuid":"766696611","full_name":"Wa-lead/CacheKing","owner":"Wa-lead","description":"Caching analysis tool","archived":false,"fork":false,"pushed_at":"2024-03-04T00:24:26.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T15:46:01.659Z","etag":null,"topics":["analysis","cache","optmization","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Wa-lead.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-03-04T00:04:44.000Z","updated_at":"2024-03-04T00:06:40.000Z","dependencies_parsed_at":"2024-03-04T01:29:53.548Z","dependency_job_id":"ce389269-e3de-4673-9a2a-4a0eeb87413e","html_url":"https://github.com/Wa-lead/CacheKing","commit_stats":null,"previous_names":["wa-lead/cacheking"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wa-lead%2FCacheKing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wa-lead%2FCacheKing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wa-lead%2FCacheKing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wa-lead%2FCacheKing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Wa-lead","download_url":"https://codeload.github.com/Wa-lead/CacheKing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244868753,"owners_count":20523591,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analysis","cache","optmization","python"],"created_at":"2024-11-28T04:16:37.560Z","updated_at":"2025-10-19T07:44:20.180Z","avatar_url":"https://github.com/Wa-lead.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# CacheKing: Analysis Tool for Computational Efficiency\n\nCacheKing serves as an insightful analysis tool that illuminates the potential efficiencies to be gained through intelligent caching in Python applications. Rather than being a direct utility for caching, CacheKing is designed to help developers identify opportunities for optimization in computational tasks. By highlighting repetitive and expensive function calls that can benefit from caching, it provides a foundation for enhancing performance in data processing, scientific calculations, and algorithmic analysis.\n\n## Concept\n\nThe core idea behind CacheKing is to analyze the execution patterns of your code, particularly focusing on functions that are called multiple times with the same arguments. CacheKing tracks these calls and simulates the impact of caching on reducing computation time and resource usage. This analysis helps in making informed decisions about implementing caching mechanisms in performance-critical sections of your projects.\n\n## Installation\n\nAs an analysis tool, CacheKing is integrated into your Python projects for the purpose of performance evaluation. Ensure Python 3.6 or later is installed for compatibility.\n\n```\npip install git+https://github.com/wa-lead/CacheKing.git\n```\n\n## Usage\n\nTo utilize CacheKing for analysis, wrap the sections of code where you suspect caching could bring performance improvements. Here's an example showing how to analyze potential caching benefits in a pathfinding scenario:\n\n```python\nfrom CacheKing import CacheKing\n\n[DEFINE YOUR PROGRAM HERE]\n\nwith CacheKing():\n\t[YOUR MAIN SCRIPT]\n```\n#\n\n## Example: Pathfinding Analysis\n\nConsider a scenario where you're calculating the shortest paths between points, factoring in obstacles. Such computations are often repeated with identical inputs, making them ideal candidates for caching.\n\n##### Example.py:\n\n```python\n\nimport pandas as pd\nimport numpy as np\nfrom functools import lru_cache\nfrom itertools import combinations\nfrom CacheKing import CacheKing\n\ndef calculate_distance(point_a, point_b):\n\treturn np.sqrt((point_b[0] - point_a[0])**2 + (point_b[1] - point_a[1])**2)\n\ndef shortest_path(point_a, point_b, obstacles_hash):\n\t# Convert hash back to obstacles list\n\tpath_distance = calculate_distance(point_a, point_b)\n\tfor obstacle in obstacles:\n\t\tdetour_distance = calculate_distance(point_a, obstacle) + calculate_distance(obstacle, point_b)\n\t\t\n\t\tpath_distance = min(path_distance, detour_distance)\n\t\t\n\treturn path_distance\n\nwith CacheKing():\n\tdata = {\n\t'location_id': range(1, 101), # 100 locations\n\t'x_coord': np.random.rand(100) * 100,\n\t'y_coord': np.random.rand(100) * 100,\n\t}\n\t\n\tlocations_df = pd.DataFrame(data)\n\tobstacles = [(20, 30), (50, 60), (70, 80)]\n\t\n\t# Calculate shortest paths between all pairs of locations\n\tpairs = combinations(locations_df['location_id'], 2)\n\tresults = []\n\t\n\tfor pair in pairs:\n\t\tloc_a = locations_df.loc[locations_df['location_id'] == pair[0], ['x_coord', 'y_coord']].iloc[0]\n\t\tloc_b = locations_df.loc[locations_df['location_id'] == pair[1], ['x_coord', 'y_coord']].iloc[0]\n\t\tdistance = shortest_path(tuple(loc_a), tuple(loc_b), obstacles)\n\t\tresults.append({'pair': pair, 'distance': distance})\n\n\tresults_df = pd.DataFrame(results)\n\tprint(results_df.head())\n```\n\n##### `CacheKing` Anslysis Output:\n\n```\n+--------------------+-------+------------+--------------+----------------------+----------------+\n|      Function      | Calls | Cache Hits | Cache Misses | Total Time (seconds) | Recommendation |\n+--------------------+-------+------------+--------------+----------------------+----------------+\n| calculate_distance | 34650 |   29106    |     5544     |        0.0124        |      High      |\n|   shortest_path    |  4950 |     0      |     4950     |        0.1279        |      Low       |\n+--------------------+-------+------------+--------------+----------------------+----------------+\n\nCaching Recommendations:\ncalculate_distance: Could benefit from caching\nshortest_path: Unlikely to benefit significantly from caching\n\n```\n\n\nThe included sample script demonstrates CacheKing's application in analyzing the efficiency of caching in a simulated pathfinding task among 100 locations. By reviewing the analysis report generated by CacheKing, you can identify which calculations are prime targets for caching, guiding your optimization efforts.\n\n## Insightful Reporting\n\nCacheKing offers detailed reports on function call patterns, highlighting:\n\n- Repetitive calls with identical inputs\n- Potential time savings through caching\n- Recommendations on caching strategies based on call frequency and computational expense\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwa-lead%2Fcacheking","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwa-lead%2Fcacheking","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwa-lead%2Fcacheking/lists"}