diff options
Diffstat (limited to 'OpenSim/Services/Connectors/Inventory')
-rw-r--r-- | OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs b/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs index db3c857..b123e9d 100644 --- a/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs +++ b/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs | |||
@@ -62,6 +62,9 @@ namespace OpenSim.Services.Connectors | |||
62 | /// </remarks> | 62 | /// </remarks> |
63 | private int m_requestTimeoutSecs = -1; | 63 | private int m_requestTimeoutSecs = -1; |
64 | 64 | ||
65 | private const double CACHE_EXPIRATION_SECONDS = 8.0; | ||
66 | private ExpiringCache<UUID, InventoryItemBase> m_ItemCache = new ExpiringCache<UUID,InventoryItemBase>(); | ||
67 | |||
65 | public XInventoryServicesConnector() | 68 | public XInventoryServicesConnector() |
66 | { | 69 | { |
67 | } | 70 | } |
@@ -511,6 +514,10 @@ namespace OpenSim.Services.Connectors | |||
511 | 514 | ||
512 | public InventoryItemBase GetItem(InventoryItemBase item) | 515 | public InventoryItemBase GetItem(InventoryItemBase item) |
513 | { | 516 | { |
517 | InventoryItemBase retrieved = null; | ||
518 | if (m_ItemCache.TryGetValue(item.ID, out retrieved)) | ||
519 | return retrieved; | ||
520 | |||
514 | try | 521 | try |
515 | { | 522 | { |
516 | Dictionary<string, object> ret = MakeRequest("GETITEM", | 523 | Dictionary<string, object> ret = MakeRequest("GETITEM", |
@@ -521,39 +528,57 @@ namespace OpenSim.Services.Connectors | |||
521 | if (!CheckReturn(ret)) | 528 | if (!CheckReturn(ret)) |
522 | return null; | 529 | return null; |
523 | 530 | ||
524 | return BuildItem((Dictionary<string, object>)ret["item"]); | 531 | retrieved = BuildItem((Dictionary<string, object>)ret["item"]); |
525 | } | 532 | } |
526 | catch (Exception e) | 533 | catch (Exception e) |
527 | { | 534 | { |
528 | m_log.Error("[XINVENTORY SERVICES CONNECTOR]: Exception in GetItem: ", e); | 535 | m_log.Error("[XINVENTORY SERVICES CONNECTOR]: Exception in GetItem: ", e); |
529 | } | 536 | } |
530 | 537 | ||
531 | return null; | 538 | m_ItemCache.AddOrUpdate(item.ID, retrieved, CACHE_EXPIRATION_SECONDS); |
539 | |||
540 | return retrieved; | ||
532 | } | 541 | } |
533 | 542 | ||
534 | public virtual InventoryItemBase[] GetMultipleItems(UUID principalID, UUID[] itemIDs) | 543 | public virtual InventoryItemBase[] GetMultipleItems(UUID principalID, UUID[] itemIDs) |
535 | { | 544 | { |
536 | InventoryItemBase[] itemArr = new InventoryItemBase[itemIDs.Length]; | 545 | InventoryItemBase[] itemArr = new InventoryItemBase[itemIDs.Length]; |
546 | // Try to get them from the cache | ||
547 | List<UUID> pending = new List<UUID>(); | ||
548 | InventoryItemBase item = null; | ||
549 | int i = 0; | ||
550 | foreach (UUID id in itemIDs) | ||
551 | { | ||
552 | if (m_ItemCache.TryGetValue(id, out item)) | ||
553 | itemArr[i++] = item; | ||
554 | else | ||
555 | pending.Add(id); | ||
556 | } | ||
557 | |||
537 | try | 558 | try |
538 | { | 559 | { |
539 | Dictionary<string, object> resultSet = MakeRequest("GETMULTIPLEITEMS", | 560 | Dictionary<string, object> resultSet = MakeRequest("GETMULTIPLEITEMS", |
540 | new Dictionary<string, object> { | 561 | new Dictionary<string, object> { |
541 | { "PRINCIPAL", principalID.ToString() }, | 562 | { "PRINCIPAL", principalID.ToString() }, |
542 | { "ITEMS", String.Join(",", itemIDs) }, | 563 | { "ITEMS", String.Join(",", pending.ToArray()) }, |
543 | { "COUNT", itemIDs.Length.ToString() } | 564 | { "COUNT", pending.Count.ToString() } |
544 | }); | 565 | }); |
545 | 566 | ||
546 | if (!CheckReturn(resultSet)) | 567 | if (!CheckReturn(resultSet)) |
547 | return null; | 568 | return null; |
548 | 569 | ||
549 | int i = 0; | 570 | // carry over index i where we left above |
550 | foreach (KeyValuePair<string, object> kvp in resultSet) | 571 | foreach (KeyValuePair<string, object> kvp in resultSet) |
551 | { | 572 | { |
552 | InventoryCollection inventory = new InventoryCollection(); | 573 | InventoryCollection inventory = new InventoryCollection(); |
553 | if (kvp.Key.StartsWith("item_")) | 574 | if (kvp.Key.StartsWith("item_")) |
554 | { | 575 | { |
555 | if (kvp.Value is Dictionary<string, object>) | 576 | if (kvp.Value is Dictionary<string, object>) |
556 | itemArr[i++] = BuildItem((Dictionary<string, object>)kvp.Value); | 577 | { |
578 | item = BuildItem((Dictionary<string, object>)kvp.Value); | ||
579 | m_ItemCache.AddOrUpdate(item.ID, item, CACHE_EXPIRATION_SECONDS); | ||
580 | itemArr[i++] = item; | ||
581 | } | ||
557 | else | 582 | else |
558 | itemArr[i++] = null; | 583 | itemArr[i++] = null; |
559 | } | 584 | } |